Skip to content

Commit af876dd

Browse files
wooldridgeaebadirad
authored andcommitted
QuickStart UI fixes for 2.x-develop (#942)
* DHFPROD-664 adjust offset, size of new entities in UI * DHFPROD-675 add index confirm for save new entity * DHFPROD-497 fix property index selection Add flags to property to keep track of what indexes are set (instead of using name). Set flags based on entity state when editor opens. Set entity state based on flags on save.
1 parent 7db2916 commit af876dd

File tree

5 files changed

+91
-75
lines changed

5 files changed

+91
-75
lines changed

quick-start/src/main/ui/app/entities/entity.model.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,8 +138,8 @@ export class Entity {
138138
},
139139
'filename': null,
140140
'hubUi': {
141-
x: 100,
142-
y: 100,
141+
x: 10,
142+
y: 115,
143143
width: 350,
144144
height: 100
145145
},

quick-start/src/main/ui/app/entities/property.model.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,11 @@ export class PropertyType {
1313

1414
// ui only
1515
showCollation: boolean = false;
16+
isPrimaryKey: boolean = false;
17+
hasElementRangeIndex: boolean = false;
18+
hasRangeIndex: boolean = false;
19+
hasWordLexicon: boolean = false;
20+
required: boolean = false;
1621

1722
UNICODE_COLLATION: string = 'http://marklogic.com/collation/codepoint';
1823

quick-start/src/main/ui/app/entity-modeler/entity-editor.component.html

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,11 @@ <h4>Properties</h4>
4444
<tbody>
4545
<tr *ngFor="let property of entity.definition.properties; let i = index">
4646
<td><input type="checkbox" [(ngModel)]="property.selected"></td>
47-
<td class="col-toggler" (click)="togglePrimaryKey(property)"><i [ngClass]="{'active': isPrimaryKey(property.name)}" class="fa fa-key"></i></td>
48-
<td class="col-toggler" (click)="toggleRangeIndex(property)"><i [ngClass]="{'active': isRangeIndex(property.name)}" class="fa fa-bolt"></i></td>
49-
<td class="col-toggler" (click)="togglePathRangeIndex(property)"><i [ngClass]="{'active': isPathRangeIndex(property.name)}" class="fa fa-code"></i></td>
50-
<td class="col-toggler" (click)="toggleWordLexicon(property)"><i [ngClass]="{'active': isWordLexicon(property.name)}" class="fa fa-won"></i></td>
51-
<td class="col-toggler" (click)="toggleRequired(property)"><i [ngClass]="{'active': isRequired(property.name)}" class="fa fa-exclamation"></i></td>
47+
<td class="col-toggler" (click)="togglePrimaryKey(property)"><i [ngClass]="{'active': property.isPrimaryKey}" class="fa fa-key"></i></td>
48+
<td class="col-toggler" (click)="property.hasElementRangeIndex = !property.hasElementRangeIndex"><i [ngClass]="{'active': property.hasElementRangeIndex}" class="fa fa-bolt"></i></td>
49+
<td class="col-toggler" (click)="property.hasRangeIndex = !property.hasRangeIndex"><i [ngClass]="{'active': property.hasRangeIndex}" class="fa fa-code"></i></td>
50+
<td class="col-toggler" (click)="property.hasWordLexicon = !property.hasWordLexicon"><i [ngClass]="{'active': property.hasWordLexicon}" class="fa fa-won"></i></td>
51+
<td class="col-toggler" (click)="property.required = !property.required"><i [ngClass]="{'active': property.required}" class="fa fa-exclamation"></i></td>
5252

5353
<td><input type="text" [(ngModel)]="property.name"></td>
5454
<td>

quick-start/src/main/ui/app/entity-modeler/entity-editor.component.ts

Lines changed: 38 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,14 @@ export class EntityEditorComponent {
5151
this.actions = actions;
5252
this.dataTypes = dataTypes;
5353
this.entityBackup = JSON.stringify(this.entity);
54+
// Set property ui flags based on entity state
55+
this.entity.definition.properties.forEach(function(property) {
56+
property.isPrimaryKey = this.entity.definition.primaryKey === property.name;
57+
property.hasElementRangeIndex = this.entity.definition.elementRangeIndex.indexOf(property.name) >= 0;
58+
property.hasRangeIndex = this.entity.definition.rangeIndex.indexOf(property.name) >= 0;
59+
property.hasWordLexicon = this.entity.definition.wordLexicon.indexOf(property.name) >= 0;
60+
property.required = this.entity.definition.required.indexOf(property.name) >= 0;
61+
}, this);
5462
}
5563

5664
getType(property: PropertyType) {
@@ -147,26 +155,6 @@ export class EntityEditorComponent {
147155
});
148156
}
149157

150-
isPrimaryKey(key: string) {
151-
return this.entity.definition.primaryKey === key;
152-
}
153-
154-
isRangeIndex(key: string) {
155-
return this.entity.definition.elementRangeIndex.indexOf(key) >= 0;
156-
}
157-
158-
isPathRangeIndex(key: string) {
159-
return this.entity.definition.rangeIndex.indexOf(key) >= 0;
160-
}
161-
162-
isWordLexicon(key: string) {
163-
return this.entity.definition.wordLexicon.indexOf(key) >= 0;
164-
}
165-
166-
isRequired(key: string) {
167-
return this.entity.definition.required.indexOf(key) >= 0;
168-
}
169-
170158
addProperty() {
171159
this.entity.definition.properties.push(new PropertyType());
172160
}
@@ -212,6 +200,29 @@ export class EntityEditorComponent {
212200

213201
saveEntity() {
214202
if (this.actions.save) {
203+
// Set entity state based on property ui flags
204+
this.entity.definition.primaryKey = null;
205+
this.entity.definition.elementRangeIndex = [];
206+
this.entity.definition.rangeIndex = [];
207+
this.entity.definition.wordLexicon = [];
208+
this.entity.definition.required = [];
209+
this.entity.definition.properties.forEach(function(property) {
210+
if (property.isPrimaryKey) {
211+
this.entity.definition.primaryKey = property.name;
212+
}
213+
if (property.hasElementRangeIndex) {
214+
this.entity.definition.elementRangeIndex.push(property.name);
215+
}
216+
if (property.hasRangeIndex) {
217+
this.entity.definition.rangeIndex.push(property.name);
218+
}
219+
if (property.hasWordLexicon) {
220+
this.entity.definition.wordLexicon.push(property.name);
221+
}
222+
if (property.required) {
223+
this.entity.definition.required.push(property.name);
224+
}
225+
}, this);
215226
this.actions.save();
216227
}
217228
this.dialog.hide();
@@ -243,28 +254,14 @@ export class EntityEditorComponent {
243254
}
244255

245256
togglePrimaryKey(property: PropertyType) {
246-
if (this.entity.definition.primaryKey === property.name) {
247-
this.entity.definition.primaryKey = null;
257+
if (property.isPrimaryKey) {
258+
property.isPrimaryKey = false;
248259
} else {
249-
this.entity.definition.primaryKey = property.name;
250-
}
251-
}
252-
253-
toggleRangeIndex(property: PropertyType) {
254-
let idx = this.entity.definition.elementRangeIndex.indexOf(property.name);
255-
if (idx >= 0) {
256-
this.entity.definition.elementRangeIndex.splice(idx, 1);
257-
} else {
258-
this.entity.definition.elementRangeIndex.push(property.name);
259-
}
260-
}
261-
262-
togglePathRangeIndex(property: PropertyType) {
263-
let idx = this.entity.definition.rangeIndex.indexOf(property.name);
264-
if (idx >= 0) {
265-
this.entity.definition.rangeIndex.splice(idx, 1);
266-
} else {
267-
this.entity.definition.rangeIndex.push(property.name);
260+
// Unset any existing primary key
261+
this.entity.definition.properties.map(function(prop) {
262+
prop.isPrimaryKey = false;
263+
});
264+
property.isPrimaryKey = true;
268265
}
269266
}
270267

@@ -314,24 +311,6 @@ export class EntityEditorComponent {
314311
}
315312
}
316313

317-
toggleWordLexicon(property: PropertyType) {
318-
let idx = this.entity.definition.wordLexicon.indexOf(property.name);
319-
if (idx >= 0) {
320-
this.entity.definition.wordLexicon.splice(idx, 1);
321-
} else {
322-
this.entity.definition.wordLexicon.push(property.name);
323-
}
324-
}
325-
326-
toggleRequired(property: PropertyType) {
327-
let idx = this.entity.definition.required.indexOf(property.name);
328-
if (idx >= 0) {
329-
this.entity.definition.required.splice(idx, 1);
330-
} else {
331-
this.entity.definition.required.push(property.name);
332-
}
333-
}
334-
335314
onDescKey($event: KeyboardEvent, propertyIndex: number) {
336315
if (
337316
(propertyIndex === (this.entity.definition.properties.length - 1)) &&

quick-start/src/main/ui/app/entity-modeler/entity-modeler.component.ts

Lines changed: 41 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -282,14 +282,7 @@ export class EntityModelerComponent implements AfterViewChecked {
282282
startEditing(entity: Entity) {
283283
this.entitiesService.editEntity(entity).subscribe(() => {
284284
this.entitiesService.saveEntity(entity).subscribe(() => {
285-
let result = this.dialogService.confirm(`Saved. Update Indexes in MarkLogic?`, 'No', 'Yes');
286-
result.subscribe(() => {
287-
this.installService.updateIndexes().subscribe(() => {
288-
this.snackbar.showSnackbar({
289-
message: 'Indexes updated.',
290-
});
291-
});
292-
}, () => {});
285+
this.confirmUpdateIndexes()
293286
});
294287
},
295288
// cancel... do nothing
@@ -353,15 +346,54 @@ export class EntityModelerComponent implements AfterViewChecked {
353346
this.saveUiState();
354347
}
355348

349+
/**
350+
* Adjust entity container coordinates based on number of entities already in UI
351+
* @param {Entity} entity
352+
*/
353+
adjustCoords(entity: Entity) {
354+
entity.hubUi.x += 20*this.entities.length;
355+
entity.hubUi.y += 30*this.entities.length;
356+
}
357+
358+
/**
359+
* Adjust entity container size based on its number of properties
360+
* @param {Entity} entity
361+
*/
362+
adjustSize(entity: Entity) {
363+
entity.hubUi.height += 22*entity.definition.properties.length;
364+
}
365+
356366
addEntity() {
357367
let entity = new Entity().defaultValues();
358368
this.entitiesService.editEntity(entity).subscribe(() => {
359-
this.entitiesService.saveEntity(entity);
369+
this.adjustCoords(entity);
370+
this.adjustSize(entity);
371+
this.entitiesService.saveEntity(entity).subscribe(() => {
372+
this.confirmUpdateIndexes();
373+
});
360374
},
361375
// cancel... do nothing
362376
() => {
363377
console.log('cancel');
364378
});
365379
}
366380

381+
/**
382+
* Display confirm dialog and update entity indexes upon confirmation
383+
*/
384+
confirmUpdateIndexes() {
385+
let result = this.dialogService.confirm(
386+
`Saved. Update Indexes in MarkLogic?`,
387+
'No',
388+
'Yes'
389+
);
390+
result.subscribe(() => {
391+
this.installService.updateIndexes().subscribe(() => {
392+
this.snackbar.showSnackbar({
393+
message: 'Indexes updated.',
394+
});
395+
});
396+
}, () => {});
397+
}
398+
367399
}

0 commit comments

Comments
 (0)