Skip to content

Commit

Permalink
Merge pull request #54 from Bitspark/group-local-operators
Browse files Browse the repository at this point in the history
Group local operators
  • Loading branch information
jm9e authored Aug 8, 2018
2 parents d2e05f2 + 450157a commit c5dcf16
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 29 deletions.
4 changes: 2 additions & 2 deletions src/app/components/operator-list.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@
<div class="sl-operator-list">
<h4>Your Local Operators</h4>
<ul class="list-group">
<li class="list-group-item"
<li class="list-group-item" [ngClass]="{'list-group-item-secondary': li.newGroup}"
*ngFor="let li of localOperatorList()">
<span class="sl-operator-name">{{ li.name }}</span>
<button class="btn btn-sm btn-link" (click)="emitOperatorSelected(li.opDef)">
<button *ngIf="!li.newGroup" class="btn btn-sm btn-link" (click)="emitOperatorSelected(li.opDef)">
<i class="fas" [ngClass]="buttonIcon"></i>
</button>
</li>
Expand Down
56 changes: 29 additions & 27 deletions src/app/components/operator-list.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,31 +20,8 @@ export class OperatorListComponent implements OnInit {
constructor() {
}

ngOnInit() {
}

public emitOperatorSelected(op: OperatorDef) {
this.operatorSelected.emit(op);
}

public localOperatorList(): Array<{ newGroup: boolean, name: string, opDef: OperatorDef }> {
return this.filteredOperatorList()
.filter(op => op.isLocal())
.sort(compareOperatorDefs)
.map(opDef => {
return {
newGroup: false,
name: opDef.getName(),
opDef: opDef,
};
});
}

public globalOperatorList(): Array<{ newGroup: boolean, name: string, opDef: OperatorDef }> {
const opList: Array<OperatorDef> = this.filteredOperatorList()
.filter(opDef => opDef.isGlobal())
.sort(compareOperatorDefs);

private static groupOperatorList(opList: Array<OperatorDef>,
opName: (n: string[]) => string): Array<{ newGroup: boolean, name: string, opDef: OperatorDef }> {
let grpName = '';
const listItems: Array<{ newGroup: boolean, name: string, opDef: OperatorDef }> = [];
for (const opDef of opList) {
Expand All @@ -53,7 +30,7 @@ export class OperatorListComponent implements OnInit {
const splitName = opDef.getName().split('.').filter(n => n !== 'slang');

if (splitName.length > 1) {
const newGrp = splitName[0];
const newGrp = splitName.shift();
if (isNewGrp = newGrp !== grpName) {
grpName = newGrp;
}
Expand All @@ -68,13 +45,16 @@ export class OperatorListComponent implements OnInit {
}
listItems.push({
newGroup: false,
name: splitName[splitName.length - 1],
name: opName(splitName),
opDef: opDef,
});
}
return listItems;
}

ngOnInit() {
}

public hasGlobals(): boolean {
return this.operatorList.find(op => op.isGlobal()) !== undefined;
}
Expand All @@ -83,4 +63,26 @@ export class OperatorListComponent implements OnInit {
return this.operatorList
.filter(opDef => opDef.getName().toLowerCase().indexOf(this.filterString.toLowerCase()) !== -1);
}

public emitOperatorSelected(op: OperatorDef) {
this.operatorSelected.emit(op);
}

public localOperatorList(): Array<{ newGroup: boolean, name: string, opDef: OperatorDef }> {
return OperatorListComponent.groupOperatorList(
this.filteredOperatorList()
.filter(op => op.isLocal())
.sort(compareOperatorDefs),
(opNameList: string[]) => opNameList.join('.'));
}

public globalOperatorList(): Array<{ newGroup: boolean, name: string, opDef: OperatorDef }> {
return OperatorListComponent.groupOperatorList(
this.filteredOperatorList()
.filter(opDef => opDef.isGlobal())
.sort(compareOperatorDefs),
(opNameList: string[]) => opNameList[opNameList.length - 1]
);
}
}

0 comments on commit c5dcf16

Please sign in to comment.