Skip to content

Commit 1c930c6

Browse files
clockworked247wooldridge
authored andcommitted
DHFPROD-1328 fix validating that new Flow name is not a duplicate
1 parent 2ea6fea commit 1c930c6

File tree

5 files changed

+48
-18
lines changed

5 files changed

+48
-18
lines changed

quick-start/src/main/ui/app/flows/flows.component.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
<li
4040
class="flow mdl-list__item"
4141
[attr.data-flow-list]="type.toUpperCase()"
42-
[ngClass]="{'active': isActiveFlow(flow)}"
42+
[ngClass]="{'active': isActiveFlow(flow, type)}"
4343
*ngFor="let flow of getFlows(entity, type)">
4444
<div (click)="setFlow(flow, type.toUpperCase())" [attr.data-flow-name]="flow.flowName">
4545
<span class="mdl-list__item-primary-content">

quick-start/src/main/ui/app/flows/flows.component.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -279,9 +279,11 @@ export class FlowsComponent implements OnInit, OnDestroy {
279279
}
280280
}
281281

282-
isActiveFlow(flow: Flow): boolean {
283-
return this.flow && this.flow.entityName === flow.entityName &&
284-
this.flow.flowName === flow.flowName;
282+
isActiveFlow(flow: Flow, flowType: string): boolean {
283+
return this.flow &&
284+
this.flow.entityName === flow.entityName &&
285+
this.flow.flowName === flow.flowName &&
286+
this.flowType.toUpperCase() === flowType.toUpperCase();
285287
}
286288

287289
isActiveEntity(entity: Entity): boolean {
@@ -324,17 +326,15 @@ export class FlowsComponent implements OnInit, OnDestroy {
324326
providers: [
325327
{ provide: 'flowType', useValue: flowType },
326328
{ provide: 'actions', useValue: actions },
327-
{ provide: 'entity', useValue: entity}
329+
{ provide: 'entity', useValue: entity },
330+
{ provide: 'flows', useValue: this.getFlows(entity, flowType) }
328331
],
329332
isModal: true
330333
});
331334
}
332335

333336
getFlows(entity: Entity, flowType: string) {
334-
if (flowType === 'Input') {
335-
return entity.inputFlows;
336-
}
337-
return entity.harmonizeFlows;
337+
return (flowType.toUpperCase() === 'INPUT') ? entity.inputFlows : entity.harmonizeFlows;
338338
}
339339

340340
getFlowType(flow: Flow, entityName: string) {

quick-start/src/main/ui/app/new-flow/new-flow.component.html

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,17 @@
1010
<form (submit)="create()">
1111
<div class="modal-body">
1212
<div class="md-dialog-content" flex layout="column">
13-
<mdl-textfield name="flowTypeInput" type="text"
13+
<mdl-textfield
14+
[ngClass]="{ 'custom-invalid' : !isNameValid }"
15+
name="flowTypeInput"
16+
type="text"
1417
required autofocus floating-label
1518
id="flowTypeInput"
1619
label="{{flowType}} Flow Name (required)"
1720
#flowTypeInput="ngModel"
18-
[(ngModel)]="flow.flowName"></mdl-textfield>
21+
[(ngModel)]="flow.flowName"
22+
(keyup)="checkName()"></mdl-textfield>
23+
<div *ngIf="!isNameValid" class="alert-text">{{ errorMsg }}</div>
1924
<ng-template [ngIf]="getMarkLogicVersion() >= 9">
2025
<label>Code Generation</label>
2126
<app-select-list
@@ -47,7 +52,7 @@
4752
</div>
4853
</div>
4954
<div class="mdl-dialog__actions">
50-
<button type="submit" [disabled]="flowTypeInput && flowTypeInput.errors && flowTypeInput.errors.required" class="mdl-button mdl-js-button mdl-button--raised mdl-button--colored mdl-js-ripple-effect">Create</button>
55+
<button type="submit" [disabled]="(flowTypeInput && flowTypeInput.errors && flowTypeInput.errors.required) || !isNameValid" class="mdl-button mdl-js-button mdl-button--raised mdl-button--colored mdl-js-ripple-effect">Create</button>
5156
<button type="button" class="mdl-button mdl-js-button mdl-button--raised mdl-js-ripple-effect" (click)="cancel()">Cancel</button>
5257
</div>
5358
</form>

quick-start/src/main/ui/app/new-flow/new-flow.component.scss

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,15 @@
1515
mdl-textfield {
1616
width: 100%;
1717
}
18+
19+
/deep/ mdl-textfield.custom-invalid input.mdl-textfield__input {
20+
border-bottom: 1px solid #a94442;
21+
}
22+
23+
.alert-text {
24+
margin-top:-20px; /* position directly under the input */
25+
color: #a94442;
26+
}
1827
}
1928

2029
/deep/ .mdl-textfield__label:after {

quick-start/src/main/ui/app/new-flow/new-flow.component.ts

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import * as _ from 'lodash';
88
import {MapService} from "../mappings/map.service";
99
import {Mapping} from "../mappings/mapping.model";
1010
import {Entity} from "../entities";
11+
import {Flow} from '../entities/flow.model';
1112

1213
@Component({
1314
selector: 'app-new-flow',
@@ -18,6 +19,9 @@ export class NewFlowComponent implements OnDestroy {
1819
flowType: string;
1920
actions: any;
2021
entity: Entity;
22+
flows: Array<Flow>;
23+
errorMsg: string;
24+
isNameValid: boolean = true;
2125

2226
scaffoldOptions = [
2327
{ label: 'Create Structure from Entity Definition', value: true },
@@ -59,22 +63,22 @@ export class NewFlowComponent implements OnDestroy {
5963
private mapService: MapService,
6064
@Inject('flowType') flowType: string,
6165
@Inject('actions') actions: any,
62-
@Inject('entity') entity: Entity
66+
@Inject('entity') entity: Entity,
67+
@Inject('flows') flows: Array<Flow>
6368
) {
6469
this.flowType = _.capitalize(flowType);
6570
this.flow = _.clone(this.emptyFlow);
6671
this.actions = actions;
6772
this.entity = entity;
73+
this.flows = flows;
6874
this.startingMappingOption = this.mappingOptions[0];
6975
this.mapService.getMappings();
7076
if (this.getMarkLogicVersion() === 8) {
7177
this.flow.useEsModel = false;
7278
} else {
73-
if (flowType === 'INPUT') {
74-
this.startingScaffoldOption = this.scaffoldOptions[1];
75-
} else {
76-
this.startingScaffoldOption = this.scaffoldOptions[0];
77-
}
79+
this.startingScaffoldOption = (flowType === 'INPUT') ?
80+
this.scaffoldOptions[1] :
81+
this.scaffoldOptions[0];
7882
}
7983
}
8084

@@ -119,4 +123,16 @@ export class NewFlowComponent implements OnDestroy {
119123
let version = this.envService.marklogicVersion.substr(0, this.envService.marklogicVersion.indexOf('.'));
120124
return parseInt(version);
121125
}
126+
127+
checkName() {
128+
let nameValid = true;
129+
let entityName = this.entity && this.entity.info && this.entity.info.title;
130+
let flowPrefix = (this.flowType.toUpperCase() === 'INPUT') ? 'an' : 'a';
131+
_.forEach(this.flows, (f) => {
132+
nameValid = (this.flow.flowName === f.flowName) ? false: nameValid;
133+
});
134+
this.errorMsg = (!nameValid) ? `Flow names must be unique. Entity "${entityName}" already contains ${flowPrefix} ${this.flowType} flow named "${this.flow.flowName}"` : '';
135+
this.isNameValid = nameValid;
136+
}
137+
122138
}

0 commit comments

Comments
 (0)