-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge GT-2095-Tool-Groups into staging
- Loading branch information
Showing
27 changed files
with
2,441 additions
and
71 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
src/app/components/edit-tool-group-resource/tool-group-resource.component.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
<div class="modal-header"> | ||
<h5>Connect Resources</h5> | ||
</div> | ||
<div class="modal-body"> | ||
<div class="tools" style="max-height: calc(100vh - 350px); overflow-y: auto"> | ||
<admin-tool-group-tool-reuseable | ||
*ngFor="let tool of tools" | ||
[tool]="tool" | ||
[resources]="resources" | ||
(updatedToolEmit)="updateTool($event)" | ||
(deleteTool)="deleteTool($event)" | ||
></admin-tool-group-tool-reuseable> | ||
</div> | ||
|
||
<button (click)="addResource()" class="btn btn-default">Add Resource</button> | ||
|
||
<div class="row"> | ||
<div class="col"> | ||
<ngb-alert type="info" [dismissible]="false" *ngIf="saving"> | ||
Saving... | ||
</ngb-alert> | ||
</div> | ||
</div> | ||
|
||
<div class="row"> | ||
<div class="col"> | ||
<ngb-alert | ||
type="danger" | ||
class="mt-2" | ||
[dismissible]="false" | ||
*ngFor="let error of errorMessage" | ||
> | ||
{{ error }} | ||
</ngb-alert> | ||
</div> | ||
</div> | ||
</div> | ||
|
||
<div class="modal-footer" style="justify-content: space-between"> | ||
<button (click)="cancel()" class="btn btn-danger">Cancel</button> | ||
<button (click)="createOrUpdate()" class="btn btn-success">Save</button> | ||
</div> |
139 changes: 139 additions & 0 deletions
139
src/app/components/edit-tool-group-resource/tool-group-resource.component.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,139 @@ | ||
import { Component, Input, OnInit } from '@angular/core'; | ||
import { NgbActiveModal } from '@ng-bootstrap/ng-bootstrap'; | ||
import { ToolGroupService } from '../../service/tool-group/tool-group.service'; | ||
import { ResourceService } from '../../service/resource/resource.service'; | ||
import { Resource } from '../../models/resource'; | ||
import { Tools, ToolGroup } from '../../models/tool-group'; | ||
|
||
interface PromisePayload { | ||
success: boolean; | ||
value?: any; | ||
error: string; | ||
} | ||
|
||
@Component({ | ||
selector: 'admin-tool-group-resource', | ||
templateUrl: './tool-group-resource.component.html', | ||
}) | ||
export class ToolGroupResourceComponent implements OnInit { | ||
@Input() toolGroup: ToolGroup; | ||
@Input() resources: Resource[] = []; | ||
selectedResources: Resource[] = []; | ||
initialTools: Tools[]; | ||
tools: Tools[]; | ||
saving = false; | ||
errorMessage: string[] = []; | ||
ruleData: any; | ||
|
||
constructor( | ||
protected toolGroupService: ToolGroupService, | ||
protected activeModal: NgbActiveModal, | ||
protected resourceService: ResourceService, | ||
) {} | ||
|
||
ngOnInit(): void { | ||
this.initialTools = this.toolGroup.tools; | ||
if (this.initialTools.length) { | ||
this.tools = this.initialTools; | ||
} else { | ||
this.tools = [this.generateNewResource()]; | ||
} | ||
|
||
if (!this.resources.length) { | ||
this.resourceService | ||
.getResources() | ||
.then((resources) => { | ||
this.resources = resources; | ||
}) | ||
.catch(this.handleError.bind(this)); | ||
} | ||
} | ||
|
||
async createOrUpdate(): Promise<void> { | ||
this.saving = true; | ||
const promises = []; | ||
if (this.tools.length) { | ||
this.tools.forEach((tool) => { | ||
const isUpdate = !!this.initialTools.find( | ||
(item) => item.id === tool.id, | ||
); | ||
promises.push( | ||
this.toolGroupService.addOrUpdateTool( | ||
this.toolGroup.id, | ||
tool.id, | ||
tool.tool.id.toString(), | ||
tool.suggestionsWeight, | ||
isUpdate, | ||
), | ||
); | ||
}); | ||
} | ||
|
||
const results: PromisePayload[] = await Promise.all( | ||
promises.map((p) => | ||
p | ||
.then((value) => ({ | ||
success: true, | ||
value, | ||
})) | ||
.catch((error) => ({ | ||
success: false, | ||
error, | ||
})), | ||
), | ||
); | ||
|
||
const invalidResults = results.filter((result) => !result.success); | ||
|
||
if (invalidResults.length) { | ||
this.saving = false; | ||
invalidResults.forEach((invalidResult) => { | ||
this.errorMessage = [...this.errorMessage, invalidResult.error]; | ||
}); | ||
} else { | ||
this.activeModal.close('closed'); | ||
} | ||
} | ||
|
||
updateTool(event: Tools): void { | ||
const toolIndex = this.tools.findIndex((tool) => tool.id === event.id); | ||
const tools = this.tools; | ||
tools[toolIndex] = event; | ||
this.tools = tools; | ||
} | ||
|
||
deleteTool(event): void { | ||
this.tools = this.tools.filter((tool) => tool.id !== event); | ||
// If ID requested to be deleted an existing tool | ||
const shouldDelete = !!this.initialTools.find((item) => item.id === event); | ||
if (shouldDelete) { | ||
this.toolGroupService.deleteTool(this.toolGroup.id, event); | ||
} | ||
} | ||
|
||
addResource(): void { | ||
this.tools = [...this.tools, this.generateNewResource()]; | ||
} | ||
|
||
generateNewResource(): Tools { | ||
return { | ||
id: this.generateId(), | ||
suggestionsWeight: '', | ||
tool: undefined, | ||
'tool-group': this.toolGroup, | ||
}; | ||
} | ||
|
||
generateId(): string { | ||
return Math.floor(Math.random() * 1000).toString(); | ||
} | ||
|
||
cancel() { | ||
this.activeModal.dismiss('dismissed'); | ||
} | ||
|
||
protected handleError(message): void { | ||
this.saving = false; | ||
this.errorMessage = [message]; | ||
} | ||
} |
57 changes: 57 additions & 0 deletions
57
src/app/components/edit-tool-group-rule-reuseable/tool-group-rule-reuseable.component.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
<div class="row mb-2"> | ||
<div class="col-12"> | ||
<label for="name" class="mb-0">{{ name }}</label> | ||
<div class="mb-2" style="display: flex; flex-wrap: wrap"> | ||
<span | ||
*ngFor="let item of selectedItems" | ||
class="badge badge-secondary mr-1 mb-1 mt-1 p-0" | ||
style="display: flex; justify-content: center; align-items: center" | ||
> | ||
<span style="padding: 5px">{{ item.name }} ({{ item.code }})</span> | ||
<button | ||
type="button" | ||
class="btn btn-secondary close" | ||
aria-label="Delete" | ||
style="padding: 5px" | ||
(click)="handleDeleteSelectedItem(item)" | ||
> | ||
<i class="fa fa-close"></i> | ||
</button> | ||
</span> | ||
</div> | ||
<select | ||
class="custom-select" | ||
[(ngModel)]="selectedItem" | ||
(ngModelChange)="handleSelectedItem($event)" | ||
> | ||
<option *ngFor="let item of items" [ngValue]="item"> | ||
{{ item.name }} ({{ item.code }}) | ||
</option> | ||
</select> | ||
</div> | ||
</div> | ||
|
||
<div class="row mb-3" *ngIf="ruleType !== 'praxis'"> | ||
<div class="col-12"> | ||
<div class="pl-4" style="position: relative"> | ||
<input | ||
id="{{ negativeInputId }}" | ||
type="checkbox" | ||
class="custom-control-input" | ||
[(ngModel)]="negativeRule" | ||
(ngModelChange)="handleNegativeRuleChange($event)" | ||
/> | ||
<label class="custom-control-label" for="{{ negativeInputId }}" | ||
>Check this to reverse this rule filters</label | ||
> | ||
</div> | ||
</div> | ||
</div> | ||
|
||
<div class="row"> | ||
<div class="col"> | ||
<ngb-alert type="danger" [dismissible]="false" *ngIf="errorMessage"> | ||
{{ errorMessage }} | ||
</ngb-alert> | ||
</div> | ||
</div> |
Oops, something went wrong.