implemented model list

This commit is contained in:
VLE2FE
2020-08-28 09:22:28 +02:00
parent f0aad664d0
commit 52e0d94e61
8 changed files with 71 additions and 9 deletions

View File

@ -25,7 +25,7 @@
</rb-icon-button>
</form>
<rb-table class="space-above">
<rb-table class="space-above space-below">
<tr>
<th>Name</th>
<th>URL</th>
@ -49,14 +49,27 @@
</td>
<td>
<span class="rb-ic rb-ic-delete clickable"
(click)="deleteModel(group.group, modelItem.name, modalDeleteConfirm)"></span>
(click)="delete(modalDeleteConfirm, modelItem.name, group.group)"></span>
</td>
</tr>
</ng-container>
</rb-table>
<rb-table>
<tr>
<th>Model files</th>
<th></th>
<th></th>
</tr>
<tr *ngFor="let file of d.arr.modelFiles">
<td>{{file.name}}</td>
<td>{{file.size | size:'M'}}</td>
<td><span class="rb-ic rb-ic-delete clickable" (click)="delete(modalDeleteConfirm, file.name)"></span></td>
</tr>
</rb-table>
<ng-template #modalDeleteConfirm>
<rb-alert alertTitle="Are you sure?" type="danger" okBtnLabel="Delete model" cancelBtnLabel="Cancel">
Do you really want to delete this model?
Do you really want to delete?
</rb-alert>
</ng-template>

View File

@ -35,13 +35,14 @@ export class ModelTemplatesComponent implements OnInit {
this.d.load('modelGroups', () => {
this.groups = this.d.arr.modelGroups.map(e => e.group);
});
this.d.load('modelFiles');
}
saveModel() {
console.log(this.modelGroup);
console.log(this.oldModelGroup);
if (this.oldModelGroup !== '' && this.modelGroup !== this.oldModelGroup) { // group was changed, delete model in old group
this.deleteModel(this.oldModelGroup, this.oldModelName);
this.deleteModel(null, this.oldModelGroup, this.oldModelName);
}
this.api.post('/model/' + this.modelGroup, this.model, () => {
this.newModel = false;
@ -53,7 +54,7 @@ export class ModelTemplatesComponent implements OnInit {
});
}
deleteModel(group, name, modal = null) {
delete(modal, name, group = null) {
new Promise(resolve => {
if (modal) {
this.modal.open(modal).then(result => {
@ -65,9 +66,16 @@ export class ModelTemplatesComponent implements OnInit {
}
}).then(res => {
if (res) {
this.api.delete(`/model/${group}/${name}`, () => {
this.loadGroups();
});
if (group) { // delete group
this.api.delete(`/model/${group}/${name}`, () => {
this.loadGroups();
});
}
else { // delete file
this.api.delete(`/model/file/${name}`, () => {
this.d.arr.modelFiles.splice(this.d.arr.modelFiles.findIndex(e => e.name === name), 1);
});
}
}
});
}