Skip to content

Commit 9bb54ad

Browse files
committed
ability add a 'multi-select' regulation
1 parent ded1651 commit 9bb54ad

9 files changed

+118
-17
lines changed

src/app/app.module.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ import { DownloadDialogComponent } from './dialogs/download-dialog.component'
2121
import { HowToDialogComponent } from './dialogs/howto-dialog.component';
2222
import { PurchaseDialogComponent } from './dialogs/purchase-dialog.component';
2323
import { ErrorsDialogComponent } from './dialogs/errors-dialog.component';
24-
import { CharterContentComponent } from './dialogs/charter-content.component';
24+
import { CharterContentComponent } from './dialogs/charter-content.component';
25+
import { MultiSelectRegsDialogComponent } from './dialogs/multi-select-regs-dialog.component';
2526
import { MessagesComponent } from './messages/messages.component';
2627
import { GraphComponent } from './graph/graph.component';
2728
import { TreeModule } from 'angular-tree-component';
@@ -67,7 +68,7 @@ import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
6768
import { FlexLayoutModule } from '@angular/flex-layout';
6869
import { injectHighlightBodyPipe, injectHighlightSectionPipe, getCommentTextPipe } from './pipes/HighlightPipe';
6970
import { getNodeColorPipe, getNodeIconPipe, getNodeIconAltPipe, getBodyPipe, getSectionPipe, getConnectionsTextPipe } from './pipes/NodePipe';
70-
import { formatDatePipe } from './pipes/FormatDatePipe'
71+
import { formatDatePipe } from './pipes/FormatDatePipe'
7172

7273
@NgModule({
7374
imports: [
@@ -128,7 +129,8 @@ import { formatDatePipe } from './pipes/FormatDatePipe'
128129
HowToDialogComponent,
129130
PurchaseDialogComponent,
130131
ErrorsDialogComponent,
131-
CharterContentComponent
132+
CharterContentComponent,
133+
MultiSelectRegsDialogComponent
132134
],
133135
declarations: [
134136
AppComponent,
@@ -148,6 +150,7 @@ import { formatDatePipe } from './pipes/FormatDatePipe'
148150
StandardMapSearchComponent,
149151
GraphComponent,
150152
CharterContentComponent,
153+
MultiSelectRegsDialogComponent,
151154

152155
injectHighlightBodyPipe,
153156
injectHighlightSectionPipe,

src/app/dialogs.service.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import { DownloadDialogComponent } from './dialogs/download-dialog.component';
1010
import { HowToDialogComponent } from './dialogs/howto-dialog.component';
1111
import { ErrorsDialogComponent } from './dialogs/errors-dialog.component';
1212
import { PurchaseDialogComponent } from './dialogs/purchase-dialog.component';
13+
import { MultiSelectRegsDialogComponent } from './dialogs/multi-select-regs-dialog.component';
1314

1415
import { CookieService } from 'ngx-cookie-service';
1516

@@ -27,16 +28,18 @@ export class DialogsService {
2728
//sideNav.close();
2829

2930
var dialogType = null;
30-
switch (dialogId) {
31+
switch (dialogId) {
3132
case 'about': dialogType = AboutDialogComponent; break;
3233
case 'changelog': dialogType = ChangeLogDialogComponent; break;
3334
case 'contribute': dialogType = ContributeDialogComponent; break;
3435
case 'credits': dialogType = CreditsDialogComponent; break;
3536
case 'disclaimer': dialogType = DisclaimerDialogComponent; break;
3637
case 'download': dialogType = DownloadDialogComponent; break;
3738
case 'howto': dialogType = HowToDialogComponent; break;
38-
case 'purchase': dialogType = PurchaseDialogComponent; break;
39-
case 'errors': dialogType = ErrorsDialogComponent; break;
39+
case 'purchase': dialogType = PurchaseDialogComponent; break;
40+
case 'errors': dialogType = ErrorsDialogComponent; break;
41+
case 'multi-select-reg': dialogType = MultiSelectRegsDialogComponent; break;
42+
4043
}
4144

4245
if (dialogType) {
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
.select-list {
2+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<h2 mat-dialog-title>Multi-select Regulations</h2>
2+
<mat-dialog-content class="mat-typography">
3+
<mat-selection-list #regs class="select-list">
4+
<mat-list-option *ngFor="let reg of dataSource" [value]="reg.id">
5+
{{reg.title}}
6+
</mat-list-option>
7+
</mat-selection-list>
8+
</mat-dialog-content>
9+
<mat-dialog-actions align="end">
10+
<button mat-button mat-dialog-close>Cancel</button>
11+
<button mat-button color="primary" [mat-dialog-close]="true" cdkFocusInitial (click)="addRegulations()">Ok</button>
12+
</mat-dialog-actions>
13+
14+
15+
<!-- Copyright 2019 Google LLC. All Rights Reserved.
16+
Use of this source code is governed by an MIT-style license that
17+
can be found in the LICENSE file at http://angular.io/license -->
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import { Component, OnInit, Input, ViewChild } from '@angular/core';
2+
import { MatList, MatSelectionList } from '@angular/material/list';
3+
import { CategoryList, GraphService } from '../graph.service';
4+
5+
@Component({
6+
selector: 'multi-select-regs-dialog',
7+
templateUrl: './multi-select-regs-dialog.component.html',
8+
styleUrls: ['./multi-select-regs-dialog.component.css']
9+
})
10+
export class MultiSelectRegsDialogComponent {
11+
dataSource: CategoryList = null;
12+
@ViewChild(MatSelectionList) regs: MatSelectionList;
13+
14+
constructor(public graphService: GraphService) {
15+
}
16+
17+
ngOnInit() {
18+
this.graphService.getDocTypes().subscribe(data => {
19+
let excludeIds = [
20+
'ISO',
21+
'All',
22+
'Multi'
23+
];
24+
25+
this.dataSource = data.filter(f => {
26+
return !excludeIds.includes(f.id);
27+
});
28+
});
29+
}
30+
31+
addRegulations() {
32+
var selection = this.regs.selectedOptions.selected;
33+
34+
// Add the All tab with a filter and override the title to "Multi"
35+
this.graphService.addTab('All', selection.map(s => {
36+
return s.value;
37+
}), 'Multi');
38+
}
39+
}

src/app/graph.service.ts

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ export class GraphService {
200200
return this.graphTabs.length < 3;
201201
}
202202

203-
public addTab(id: string) {
203+
public addTab(id: string, filterTopLevelKeys: string[] = null, customName: string = null) {
204204
if (!this.canAdd)
205205
return;
206206

@@ -209,7 +209,21 @@ export class GraphService {
209209
var newTab = new GraphTab(this, null, doc);
210210

211211
newTab.nodes = doc.children;
212-
newTab.column.nodes = doc.children;
212+
213+
// Filter the top level nodes if desired
214+
if (filterTopLevelKeys) {
215+
newTab.nodes = doc.children.filter(c => {
216+
var rootKey = c.id.replace(/_/g, ''); // The 'all' structure has _, where the menu choice has those stripped. Remove them for comparison.
217+
return filterTopLevelKeys.includes(rootKey);
218+
});
219+
}
220+
221+
// Override the tab name if desired
222+
if (customName)
223+
newTab.title = customName;
224+
225+
// Reference this data from the column view.
226+
newTab.column.nodes = newTab.nodes;
213227

214228
this.graphTabs.push(newTab);
215229
this.ensureISOIsInMiddle();

src/app/graph/graph.component.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
<span class="example-spacer"></span>
1717
<button mat-button aria-label="Add Regulation Tab" [matMenuTriggerFor]="menu" class="add-button" [class.button-disabled]="!graphService.canAdd"><mat-icon>add_box</mat-icon></button>
1818
<mat-menu #menu="matMenu">
19-
<button mat-menu-item *ngFor="let d of getMenuOptions()" (click)="graphService.addTab(d.id)">{{d.title}}</button>
19+
<button mat-menu-item *ngFor="let d of getMenuOptions()" (click)="addTab(d.id)">{{d.title}}</button>
2020
</mat-menu>
2121
</div>
2222

src/app/graph/graph.component.ts

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -74,16 +74,28 @@ export class GraphComponent implements OnInit, OnDestroy {
7474
}
7575

7676
public getMenuOptions(): any[] {
77-
var result = [];
77+
var result = [];
7878

79-
if (this.graphService.canAdd)
80-
{
81-
for (var t of this.graphCategories)
82-
if (!this.graphService.graphTabs.find(g => g.id == t.id))
83-
result.push(t);
84-
}
79+
if (this.graphService.canAdd) {
80+
const existing = this.graphService.graphTabs.map(t => t.id);
81+
for (var t of this.graphCategories)
82+
if ((t.id == 'Multi' || t.id == 'All') && (existing.includes('All') || existing.includes('Multi'))) {
83+
// dont compare all to multi, or either to itself
84+
}
85+
else if (!existing.includes(t.id)) {
86+
// if it doesnt exist, add it
87+
result.push(t);
88+
}
89+
}
90+
91+
return result;
92+
}
8593

86-
return result;
94+
private addTab(id: string) {
95+
if (id == 'Multi')
96+
this.dialogService.openDialog('multi-select-reg');
97+
else
98+
this.graphService.addTab(id);
8799
}
88100

89101
//private DrawTable(data: DAG) {

utils/importer.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -362,6 +362,17 @@ function importXlsx() {
362362

363363
allDocs.push(allDoc);
364364

365+
// Create multi-doc metadata
366+
var multiDoc = {
367+
"type": "Multi-Select",
368+
"id": "Multi",
369+
"rev": 1,
370+
"children": [],
371+
"langs": []
372+
};
373+
374+
allDocs.push(multiDoc);
375+
365376
var db = {
366377
"changelog": changeLog,
367378
"docs": allDocs

0 commit comments

Comments
 (0)