workspace-ionic-app/src/app/ws/ws.page.ts

65 lines
1.6 KiB
TypeScript
Raw Normal View History

2023-02-16 17:18:54 +01:00
import { Component, OnInit } from '@angular/core';
import { Platform, AlertController, ToastController } from '@ionic/angular';
import { Router, ActivatedRoute } from '@angular/router';
import { FileOpener } from '@awesome-cordova-plugins/file-opener/ngx';
2023-02-20 18:06:39 +01:00
import { StoragehubService } from '../storagehub.service';
2023-02-23 18:11:45 +01:00
import { WSItem } from '../model/ws-item';
2023-02-24 17:28:40 +01:00
import { Item } from '../model/item.model';
2023-02-16 17:18:54 +01:00
@Component({
selector: 'app-ws',
2023-02-20 18:06:39 +01:00
providers: [StoragehubService],
2023-02-16 17:18:54 +01:00
templateUrl: 'ws.page.html',
2023-02-20 18:06:39 +01:00
styleUrls: ['ws.page.scss'],
2023-02-16 17:18:54 +01:00
})
2023-02-20 18:06:39 +01:00
export class WsPage implements OnInit {
2023-02-16 17:18:54 +01:00
2023-02-24 17:28:40 +01:00
values: WSItem[] = [];
2023-02-20 18:06:39 +01:00
folderid: string | undefined;
2023-02-24 17:28:40 +01:00
item : WSItem | undefined ;
2023-02-20 18:06:39 +01:00
constructor(private storagehub: StoragehubService,
2023-02-16 17:18:54 +01:00
private router: Router,
2023-02-20 18:06:39 +01:00
private route: ActivatedRoute) { }
ngOnInit() {
this.folderid = this.route.snapshot.paramMap.get('folderid') || undefined;
if (!this.folderid)
this.storagehub.getWsRoot().subscribe(
(res) => this.onSuccess(res)
);
else
this.storagehub.getItem(this.folderid).subscribe(
(res) => {
2023-02-24 17:28:40 +01:00
this.item = new WSItem(res);
2023-02-20 18:06:39 +01:00
this.onSuccess(res);
}
);
}
2023-02-16 17:18:54 +01:00
2023-02-20 18:06:39 +01:00
private onSuccess(item: Item) {
this.storagehub.getChildren(item.id, false).subscribe(
2023-02-24 17:28:40 +01:00
(res) => {
const tmpItems$ : WSItem[] = []
res.forEach(i => tmpItems$.push(new WSItem(i)));
this.values = tmpItems$;
}
2023-02-20 18:06:39 +01:00
)
2023-02-16 17:18:54 +01:00
}
2023-02-24 17:28:40 +01:00
public getValues(): WSItem[] {
return this.values;
2023-02-16 17:18:54 +01:00
}
2023-02-24 17:28:40 +01:00
openFolder(item: WSItem) {
this.router.navigateByUrl(`tabs/ws/${item.item.id}`);
2023-02-16 17:18:54 +01:00
}
2023-02-23 18:11:45 +01:00
public getCurrentItem() : WSItem | undefined{
2023-02-24 17:28:40 +01:00
return this.item;
2023-02-20 18:06:39 +01:00
}
2023-02-16 17:18:54 +01:00
}