workspace-ionic-app/src/app/ws-viewer/ws-viewer.component.ts

108 lines
2.9 KiB
TypeScript
Raw Normal View History

import { CommonModule } from '@angular/common';
import { Component, Input, OnInit } from '@angular/core';
import { MatIconModule } from '@angular/material/icon';
import { IonicModule, ModalController } from '@ionic/angular';
2023-03-15 17:16:06 +01:00
import { EventService } from '../event.service';
2023-03-01 12:06:56 +01:00
import { Sorting, SortName, SortType } from '../model/sorting';
import { WSItem } from '../model/ws-item';
import { StoragehubService } from '../storagehub.service';
@Component({
standalone: true,
selector: 'app-ws-viewer',
providers: [StoragehubService],
templateUrl: './ws-viewer.component.html',
styleUrls: ['./ws-viewer.component.scss'],
imports: [
CommonModule, IonicModule, MatIconModule
]
})
export class WsViewerComponent implements OnInit {
constructor(private storagehub: StoragehubService,
2023-03-15 17:16:06 +01:00
private modalCtrl: ModalController, private eventService: EventService ) { }
2023-02-26 13:10:00 +01:00
@Input() notClickableIds: string[] = [];
@Input() notSelectableIds: string[] = [];
@Input() finishLabel: string = "Confirm";
@Input() title: string = "Operation";
2023-02-26 13:10:00 +01:00
@Input() onSelected :Function = () => {};
currentItem: WSItem | undefined;
2023-02-26 13:10:00 +01:00
anchestors: WSItem[] | undefined ;
items: WSItem[] | undefined = undefined;
2023-02-26 13:10:00 +01:00
ngOnInit() {
2023-02-26 13:10:00 +01:00
this.loadDocuments();
}
2023-02-26 13:10:00 +01:00
2023-03-15 17:16:06 +01:00
loadDocuments() {
if (this.currentItem) {
2023-03-08 17:13:03 +01:00
this.storagehub.getChildren(this.currentItem.item.id).then( (obs) => obs.subscribe(
(res) => {
const tmpItems$: WSItem[] = []
res.forEach(i => tmpItems$.push(new WSItem(i)));
2023-03-01 12:06:56 +01:00
this.items = tmpItems$.sort(Sorting.getSortFunction(SortName.FolderFirst, SortType.Asc));
})
2023-03-08 17:13:03 +01:00
);
} else
2023-03-08 17:13:03 +01:00
this.storagehub.getWsRoot().then( (obs) => obs.subscribe(
(res) => this.addVresToWs(new WSItem(res))
2023-03-08 17:13:03 +01:00
));
}
addVresToWs(wsRoot: WSItem) {
2023-03-08 17:13:03 +01:00
this.storagehub.getVres().then( (obs) => obs.subscribe(
(res) => {
const tmpItems$: WSItem[] = [wsRoot]
res.forEach(i => tmpItems$.push(new WSItem(i)));
this.items = tmpItems$;
2023-03-08 17:13:03 +01:00
}));
}
2023-02-26 13:10:00 +01:00
isCurrentItemSelectable(){
return this.currentItem && !this.notSelectableIds.includes(this.currentItem.item.id);
}
isItemClickable(item: WSItem){
return item.isFolder() && !this.notClickableIds.includes(item.item.id);
}
itemClicked(item: WSItem) {
2023-02-26 13:10:00 +01:00
this.items = undefined;
if (this.currentItem)
this.anchestors?.push(this.currentItem);
else this.anchestors =[]
this.currentItem = item;
this.ngOnInit();
}
2023-02-26 13:10:00 +01:00
backClicked() {
this.items = undefined;
if (this.anchestors?.length == 0){
this.anchestors = undefined;
this.currentItem = undefined;
} else {
var tmpitem = this.anchestors?.pop();
this.currentItem = tmpitem;
}
2023-03-15 17:16:06 +01:00
this.loadDocuments();
2023-02-26 13:10:00 +01:00
}
cancel() {
return this.modalCtrl.dismiss(null, 'cancel');
}
confirm() {
2023-02-26 13:10:00 +01:00
this.onSelected(this.currentItem);
return this.modalCtrl.dismiss(null, 'confirm');
}
2023-03-01 12:06:56 +01:00
}