Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import { ChangeDetectionStrategy, Component, Input, OnInit } from '@angular/core';
import { fadeIn, fadeInOut } from '../../../shared/animations/fade';
import { Item } from '../../../core/shared/item.model';
import { Router } from '@angular/router';
@Component({
selector: 'ds-item-status',
templateUrl: './item-status.component.html',
changeDetection: ChangeDetectionStrategy.OnPush,
animations: [
fadeIn,
fadeInOut
]
})
/**
* Component for displaying an item's status
*/
export class ItemStatusComponent implements OnInit {
/**
* The item to display the status for
*/
@Input() item: Item;
/**
* The data to show in the status
*/
statusData: any;
/**
* The keys of the data (to loop over)
*/
statusDataKeys;
/**
* The possible actions that can be performed on the item
* key: id value: url to action's component
*/
actions: any;
/**
* The keys of the actions (to loop over)
*/
actionsKeys;
constructor(private router: Router) {
}
ngOnInit(): void {
this.statusData = Object.assign({
id: this.item.id,
handle: this.item.handle,
lastModified: this.item.lastModified
});
this.statusDataKeys = Object.keys(this.statusData);
/*
The key is used to build messages
i18n example: 'item.edit.tabs.status.buttons.<key>.label'
The value is supposed to be a href for the button
*/
this.actions = Object.assign({
// TODO: Create mapping component on item level
mappedCollections: this.getCurrentUrl() + '/'
});
this.actionsKeys = Object.keys(this.actions);
}
/**
* Get the url to the simple item page
* @returns {string} url
*/
getItemPage(): string {
return this.router.url.substr(0, this.router.url.lastIndexOf('/'));
}
/**
* Get the current url without query params
* @returns {string} url
*/
getCurrentUrl(): string {
if (this.router.url.indexOf('?') > -1) {
return this.router.url.substr(0, this.router.url.indexOf('?'));
} else {
return this.router.url;
}
}
}