Newer
Older
import { Component, OnInit, Input, ViewChild, Output, EventEmitter } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { LANG } from '../translate.component';
import { NotificationService } from '../notification.service';
import { MatDialog, MatDialogRef } from '@angular/material/dialog';
import { MatMenuTrigger } from '@angular/material/menu';
import { Router } from '@angular/router';
import { ActionsService } from './actions.service';
import { Subscription } from 'rxjs';
@Component({
selector: 'app-actions-list',
templateUrl: "actions-list.component.html",
styleUrls: ['actions-list.component.scss']
})
export class ActionsListComponent implements OnInit {
lang: any = LANG;
loading: boolean = false;
@ViewChild(MatMenuTrigger, { static: false }) contextMenu: MatMenuTrigger;
@Output() triggerEvent = new EventEmitter<string>();
contextMenuPosition = { x: '0px', y: '0px' };
contextMenuTitle = '';
folderList: any[] = [];
@Input('selectedRes') selectedRes: any;
@Input('totalRes') totalRes: number;
@Input('contextMode') contextMode: boolean;
@Input('currentBasketInfo') currentBasketInfo: any;
@Input('currentResource') currentResource: any = {};
@Output('refreshEvent') refreshEvent = new EventEmitter<string>();
@Output('refreshEventAfterAction') refreshEventAfterAction = new EventEmitter<string>();
@Output('refreshPanelFolders') refreshPanelFolders = new EventEmitter<string>();
constructor(
public http: HttpClient,
private notify: NotificationService,
public dialog: MatDialog,
private router: Router,
private actionService: ActionsService
) { }
dialogRef: MatDialogRef<any>;
open(x: number, y: number, row: any) {
// Adjust the menu anchor position
this.contextMenuPosition.x = x + 'px';
this.contextMenuPosition.y = y + 'px';
this.currentResource = row;
this.contextMenuTitle = row.chrono;
this.contextResId = row.resId;
this.folderList = row.folders !== undefined ? row.folders : [];
// Opens the menu
this.contextMenu.openMenu();
// prevents default
return false;
}
launchEvent(action: any, row: any) {
this.currentAction = action;
this.arrRes = this.selectedRes;
if (this.contextMode && this.selectedRes.length > 1) {
this.contextMenuTitle = '';
this.contextResId = 0;
if (row !== undefined) {
this.contextMenuTitle = row.chrono;
this.actionService.launchAction(action, this.currentBasketInfo.ownerId, this.currentBasketInfo.groupId, this.currentBasketInfo.basketId, this.selectedRes, this.currentResource, true);
if (JSON.stringify(this.basketInfo) != JSON.stringify(this.currentBasketInfo)) {
this.basketInfo = JSON.parse(JSON.stringify(this.currentBasketInfo));
this.http.get('../../rest/resourcesList/users/' + this.currentBasketInfo.ownerId + '/groups/' + this.currentBasketInfo.groupId + '/baskets/' + this.currentBasketInfo.basketId + '/actions')
.subscribe((data: any) => {
if (data.actions.length > 0) {
this.actionsList = data.actions;
} else {
this.actionsList = [{
id: 0,
component: ''
}];
}
this.loading = false;
}, (err: any) => {
this.notify.handleErrors(err);
});
refreshList() {
this.refreshEvent.emit();
}
this.refreshPanelFolders.emit();
}