Skip to content

Commit

Permalink
Merge GT-2095-Tool-Groups into staging
Browse files Browse the repository at this point in the history
  • Loading branch information
stage-branch-merger[bot] authored Oct 23, 2023
2 parents 2388cef + a8a325b commit 9409ef5
Show file tree
Hide file tree
Showing 27 changed files with 2,441 additions and 71 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ jobs:
- name: Run Test with CodeCov
run: yarn test:codecov
- name: Code coverage test
uses: codecov/codecov-action@v1.1.1
uses: codecov/codecov-action@v3.1.1

deploy:
name: Deployment
Expand Down
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"test": "ng test",
"test:codecov": "ng test --watch=false --browsers=ChromeHeadless --code-coverage",
"lint": "ng lint",
"lint:fix": "ng lint --fix",
"lint:type": "ng lint --type-check",
"e2e": "ng e2e",
"prettier:check": "prettier '{{src,e2e,__{tests,mocks}__}/**/*.{js,json,ts,tsx,html},./*.{js,json,ts,tsx,yml,html}}' --list-different",
Expand All @@ -33,6 +34,7 @@
"angular2-uuid": "1.1.1",
"components-font-awesome": "4.7.0",
"core-js": "2.6.12",
"countries-list": "^3.0.5",
"jsonapi-datastore": "0.4.0-beta",
"ng2-ace-editor": "0.3.9",
"ng2-file-upload": "1.4.0",
Expand All @@ -54,7 +56,7 @@
"husky": "7.0.4",
"jasmine-core": "2.99.1",
"jasmine-spec-reporter": "7.0.0",
"karma": "6.3.17",
"karma": "6.4.1",
"karma-chrome-launcher": "3.1.1",
"karma-cli": "2.0.0",
"karma-coverage": "2.2.0",
Expand Down
6 changes: 6 additions & 0 deletions src/app/app-routing.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { AttachmentsComponent } from './components/attachments/attachments.compo
import { AuthGuardService } from './service/auth-guard/auth-guard.service';
import { OktaLoginComponent } from './components/okta-login/okta-login.component';
import { MyAccountComponent } from './components/my-account/my-account.component';
import { ToolGroupsComponent } from './components/tool-groups/tool-groups.component';

const routes: Routes = [
{ path: '', redirectTo: '/translations', pathMatch: 'full' },
Expand All @@ -30,6 +31,11 @@ const routes: Routes = [
component: MyAccountComponent,
canActivate: [AuthGuardService],
},
{
path: 'tool-groups',
component: ToolGroupsComponent,
canActivate: [AuthGuardService],
},
{
path: 'auth/okta',
component: OktaLoginComponent,
Expand Down
3 changes: 3 additions & 0 deletions src/app/app.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ <h5>{{ title }}</h5>
<a *ngIf="sessionReady$ | async" routerLink="/attachments" class="nav-link"
>Attachments</a
>
<a *ngIf="sessionReady$ | async" routerLink="/tool-groups" class="nav-link"
>Tool Groups</a
>
<a *ngIf="sessionReady$ | async" routerLink="/languages" class="nav-link"
>Languages</a
>
Expand Down
24 changes: 24 additions & 0 deletions src/app/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,16 @@ import { OAuthModule } from 'angular-oauth2-oidc';
import { HttpClientModule } from '@angular/common/http';
import { OktaLoginErrorComponent } from './components/okta-login-error/okta-login-error.component';
import { MyAccountComponent } from './components/my-account/my-account.component';
import { ToolGroupsComponent } from './components/tool-groups/tool-groups.component';
import { ToolGroupService } from './service/tool-group/tool-group.service';
import { CreateToolGroupComponent } from './components/edit-tool-group/create-tool-group/create-tool-group.component';
import { ToolGroupComponent } from './components/tool-group/tool-group.component';
import { LanguageBCP47Service } from './service/languages-bcp47-tag.service';
import { UpdateToolGroupComponent } from './components/edit-tool-group/update-tool-group/update-resource.component';
import { ToolGroupRuleComponent } from './components/edit-tool-group-rule/tool-group-rule.component';
import { ToolGroupRuleReuseableComponent } from './components/edit-tool-group-rule-reuseable/tool-group-rule-reuseable.component';
import { ToolGroupToolReuseableComponent } from './components/edit-tool-group-tool-reuseable/tool-group-tool-reuseable.component';
import { ToolGroupResourceComponent } from './components/edit-tool-group-resource/tool-group-resource.component';

@NgModule({
declarations: [
Expand Down Expand Up @@ -82,6 +92,14 @@ import { MyAccountComponent } from './components/my-account/my-account.component
OktaLoginComponent,
OktaLoginErrorComponent,
MyAccountComponent,
ToolGroupsComponent,
CreateToolGroupComponent,
ToolGroupComponent,
UpdateToolGroupComponent,
ToolGroupRuleComponent,
ToolGroupRuleReuseableComponent,
ToolGroupResourceComponent,
ToolGroupToolReuseableComponent,
],
imports: [
AceEditorModule,
Expand Down Expand Up @@ -113,6 +131,8 @@ import { MyAccountComponent } from './components/my-account/my-account.component
CustomManifestService,
UserAuthSessionService,
AttributeTranslationService,
ToolGroupService,
LanguageBCP47Service,
],
entryComponents: [
UpdateResourceComponent,
Expand All @@ -130,6 +150,10 @@ import { MyAccountComponent } from './components/my-account/my-account.component
LoginComponent,
MultipleDraftGeneratorComponent,
OktaLoginErrorComponent,
CreateToolGroupComponent,
UpdateToolGroupComponent,
ToolGroupRuleComponent,
ToolGroupResourceComponent,
],
bootstrap: [AppComponent],
})
Expand Down
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>
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];
}
}
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>
Loading

0 comments on commit 9409ef5

Please sign in to comment.