Skip to content

Commit cb671cf

Browse files
fix dschnelldavis#274 Button close does not exist in the NoFramework Component.
This is bug fixing commit.
1 parent 1a5bfee commit cb671cf

File tree

1 file changed

+50
-3
lines changed

1 file changed

+50
-3
lines changed
Lines changed: 50 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,62 @@
1-
import { Component, Input } from '@angular/core';
1+
import { Component, Input, OnInit } from '@angular/core';
2+
import * as _ from 'lodash';
3+
import { JsonSchemaFormService } from '../../json-schema-form.service';
24

35
@Component({
46
selector: 'no-framework',
57
template: `
8+
<button style='float:right;clear: right;' *ngIf="showRemoveButton"
9+
type="button"
10+
(click)="removeItem()">
11+
<span aria-hidden="true">&times;</span>
12+
</button>
613
<select-widget-widget
714
[dataIndex]="dataIndex"
815
[layoutIndex]="layoutIndex"
9-
[layoutNode]="layoutNode"></select-widget-widget>`,
16+
[layoutNode]="layoutNode"></select-widget-widget>
17+
`,
1018
})
11-
export class NoFrameworkComponent {
19+
export class NoFrameworkComponent implements OnInit {
20+
21+
options: any; // Options used in this framework
22+
parentArray: any = null;
23+
isOrderable = false;
24+
1225
@Input() layoutNode: any;
1326
@Input() layoutIndex: number[];
1427
@Input() dataIndex: number[];
28+
29+
constructor(
30+
public jsf: JsonSchemaFormService
31+
) { }
32+
33+
ngOnInit() {
34+
this.options = _.cloneDeep(this.layoutNode.options);
35+
if (this.layoutNode.arrayItem && this.layoutNode.type !== '$ref') {
36+
this.parentArray = this.jsf.getParentNode(this);
37+
if (this.parentArray) {
38+
this.isOrderable = this.layoutNode.arrayItemType === 'list' &&
39+
!this.options.readonly && this.parentArray.options.orderable;
40+
}
41+
}
42+
}
43+
44+
45+
get showRemoveButton(): boolean {
46+
if (!this.options.removable || this.options.readonly ||
47+
this.layoutNode.type === '$ref'
48+
) { return false; }
49+
if (this.layoutNode.recursiveReference) { return true; }
50+
if (!this.layoutNode.arrayItem || !this.parentArray) { return false; }
51+
// If array length <= minItems, don't allow removing any items
52+
return this.parentArray.items.length - 1 <= this.parentArray.options.minItems ? false :
53+
// For removable list items, allow removing any item
54+
this.layoutNode.arrayItemType === 'list' ? true :
55+
// For removable tuple items, only allow removing last item in list
56+
this.layoutIndex[this.layoutIndex.length - 1] === this.parentArray.items.length - 2;
57+
}
58+
59+
removeItem() {
60+
this.jsf.removeItem(this);
61+
}
1562
}

0 commit comments

Comments
 (0)