Skip to content

Commit

Permalink
Feature/1651/register tool alerts (#366)
Browse files Browse the repository at this point in the history
* Hook up refresh and error alerts properly for register entry

* Remove test because no longer true
  • Loading branch information
garyluu authored Jul 27, 2018
1 parent 9fabe39 commit 3e03f00
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 65 deletions.
41 changes: 23 additions & 18 deletions src/app/container/register-tool/register-tool.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,19 @@
import { HttpErrorResponse } from '@angular/common/http';
import { Injectable } from '@angular/core';
import { Router } from '@angular/router';
// This line is super important for jQuery to work across the website for some reason
import * as $ from 'jquery';
import { BehaviorSubject } from 'rxjs';

import { ContainerService } from './../../shared/container.service';
import { Repository } from './../../shared/enum/Repository.enum';
import { StateService } from './../../shared/state.service';
import { ContainersService } from './../../shared/swagger/api/containers.service';
import { HostedService } from './../../shared/swagger/api/hosted.service';
import { MetadataService } from './../../shared/swagger/api/metadata.service';
import { DockstoreTool } from './../../shared/swagger/model/dockstoreTool';
import { Tool } from './tool';
import { HostedService } from './../../shared/swagger/api/hosted.service';
// This line is super important for jQuery to work across the website for some reason
import * as $ from 'jquery';
import { finalize } from 'rxjs/operators';

@Injectable()
export class RegisterToolService {
Expand Down Expand Up @@ -95,21 +96,25 @@ export class RegisterToolService {
}

registerTool(newTool: Tool, customDockerRegistryPath) {
this.setTool(newTool);
const normalizedToolObj: DockstoreTool = this.getNormalizedToolObj(newTool, customDockerRegistryPath);
this.containersService.registerManual(normalizedToolObj).subscribe(response => {
this.setToolRegisterError(null);
this.stateService.setRefreshMessage('Registering new tool...');
this.containersService.refresh(response.id).subscribe((refreshResponse: DockstoreTool) => {
this.stateService.setRefreshMessage(null);
this.setIsModalShown(false);
this.containerService.addToTools(this.tools, refreshResponse);
this.containerService.setTool(refreshResponse);
this.router.navigateByUrl('/my-tools' + '/' + refreshResponse.tool_path);
});
// Use types instead
}, error => this.setToolRegisterError(error)
);
this.setToolRegisterError(null);
this.setTool(newTool);
this.stateService.setRefreshMessage('Registering new tool...');
const normalizedToolObj: DockstoreTool = this.getNormalizedToolObj(newTool, customDockerRegistryPath);
this.containersService.registerManual(normalizedToolObj)
.subscribe((registeredDockstoreTool: DockstoreTool) => {
this.stateService.setRefreshMessage('Refreshing new tool...');
this.containersService.refresh(registeredDockstoreTool.id).pipe(finalize(() => {
this.stateService.setRefreshMessage(null);
})).subscribe((refreshedDockstoreTool: DockstoreTool) => {
this.setIsModalShown(false);
this.containerService.addToTools(this.tools, refreshedDockstoreTool);
this.containerService.setTool(refreshedDockstoreTool);
this.router.navigateByUrl('/my-tools' + '/' + refreshedDockstoreTool.tool_path);
}, (error: HttpErrorResponse) => this.setToolRegisterError(error));
}, (error: HttpErrorResponse) => {
this.stateService.setRefreshMessage(null);
this.setToolRegisterError(error);
});
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,12 +74,7 @@ describe('Service: RegisterWorkflowModal', () => {
service.setWorkflowRepository('asdf');
service.workflow.subscribe(workflow => expect(workflow).toEqual(expectedWorkflow));
}));
it('should set register error and clear refreshing state', inject([RegisterWorkflowModalService, StateService],
(service: RegisterWorkflowModalService, stateService: StateService) => {
service.setWorkflowRegisterError('oh no!', 'oh yes');
service.workflowRegisterError$.subscribe(error => expect(error).toEqual(expectedError));
stateService.refreshMessage$.subscribe(refreshMessage => expect(refreshMessage).toBeFalsy());
}));

it('should set register workflow and clear refreshing state and error', inject([RegisterWorkflowModalService, StateService],
(service: RegisterWorkflowModalService, stateService: StateService) => {
service.registerWorkflow();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,11 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { HttpErrorResponse } from '@angular/common/http';
import { Injectable } from '@angular/core';
import { Router } from '@angular/router';
import { BehaviorSubject, Observable } from 'rxjs';
import { finalize } from 'rxjs/operators';

import { DescriptorLanguageService } from './../../shared/entry/descriptor-language.service';
import { StateService } from './../../shared/state.service';
Expand Down Expand Up @@ -59,13 +61,25 @@ export class RegisterWorkflowModalService {
this.isModalShown$.next(isModalShown);
}

setWorkflowRegisterError(message: any, errorDetails) {
const error = {
message: message,
errorDetails: errorDetails
};
this.workflowRegisterError$.next(error);
this.stateService.refreshMessage$.next(null);
setWorkflowRegisterError(error: HttpErrorResponse) {
let errorObj = null;
if (error) {
if (error.status === 0) {
errorObj = {
message: 'The webservice is currently down, possibly due to load. Please wait and try again later.',
errorDetails: ''
};
} else {
errorObj = {
message: 'The webservice encountered an error trying to create this ' +
'workflow, please ensure that the workflow attributes are ' +
'valid.',
errorDetails: '[HTTP ' + error.status + '] ' + error.statusText + ': ' +
error.error
};
}
}
this.workflowRegisterError$.next(errorObj);
}

setWorkflow(workflow: Workflow) {
Expand All @@ -78,67 +92,50 @@ export class RegisterWorkflowModalService {
}

registerWorkflow() {
this.stateService.setRefreshMessage('Registering workflow...');
this.clearWorkflowRegisterError();
this.stateService.setRefreshMessage('Registering new workflow...');
this.workflowsService.manualRegister(
this.actualWorkflow.repository,
this.actualWorkflow.gitUrl,
this.actualWorkflow.workflow_path,
this.actualWorkflow.workflowName,
this.actualWorkflow.descriptorType,
this.actualWorkflow.defaultTestParameterFilePath).subscribe(result => {
this.workflowsService.refresh(result.id).subscribe(refreshResult => {
this.stateService.setRefreshMessage('Refreshing new workflow...');
this.workflowsService.refresh(result.id).pipe(finalize(() => {
this.stateService.setRefreshMessage(null);
})).subscribe(refreshResult => {
this.workflows.push(refreshResult);
this.workflowService.setWorkflows(this.workflows);
this.stateService.setRefreshMessage(null);
this.setIsModalShown(false);
this.clearWorkflowRegisterError();
this.router.navigateByUrl('/my-workflows' + '/' + refreshResult.full_workflow_path);
}, error => this.stateService.setRefreshMessage(null));
}, error => this.setWorkflowRegisterError(error));
}, error => {
if (error) {
if (error.status === 0) {
this.setWorkflowRegisterError('The webservice is currently down, possibly due to load. ' +
'Please wait and try again later.', '');
} else {
this.setWorkflowRegisterError('The webservice encountered an error trying to create this ' +
'workflow, please ensure that the workflow attributes are ' +
'valid and the same image has not already been registered.', '[HTTP ' + error.status + '] ' + error.statusText + ': ' +
error.error);
}
}
}
);
this.stateService.setRefreshMessage(null);
this.setWorkflowRegisterError(error);
});
}

/**
* Registers a hosted workflow
* @param hostedWorkflow hosted workflow object
*/
registerHostedWorkflow(hostedWorkflow) {
this.stateService.setRefreshMessage('Registering workflow...');
this.clearWorkflowRegisterError();
this.stateService.setRefreshMessage('Registering new workflow...');
this.hostedService.createHostedWorkflow(
hostedWorkflow.name,
hostedWorkflow.descriptorType).subscribe(result => {
hostedWorkflow.descriptorType).pipe(finalize(() => {
this.stateService.setRefreshMessage(null);
})).subscribe(result => {
this.workflows.push(result);
this.workflowService.setWorkflows(this.workflows);
this.stateService.setRefreshMessage(null);
this.setIsModalShown(false);
this.clearWorkflowRegisterError();
this.router.navigateByUrl('/my-workflows' + '/' + result.full_workflow_path);
}, error => {
if (error) {
if (error.status === 0) {
this.setWorkflowRegisterError('The webservice is currently down, possibly due to load. ' +
'Please wait and try again later.', '');
} else {
this.setWorkflowRegisterError('The webservice encountered an error trying to create this ' +
'workflow, please ensure that the workflow attributes are ' +
'valid and the same workflow has not already been registered.', '[HTTP ' + error.status + '] ' + error.statusText + ': ' +
error.error);
}
}
}
);
this.setWorkflowRegisterError(error);
});
}

friendlyRepositoryKeys(): Array<string> {
Expand Down

0 comments on commit 3e03f00

Please sign in to comment.