This repository has been archived by the owner on Nov 22, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 15
/
dataservice-card.component.ts
161 lines (137 loc) · 4.97 KB
/
dataservice-card.component.ts
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
/**
* @license
* Copyright 2017 JBoss Inc
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { Component, EventEmitter, Input, OnInit, Output, ViewEncapsulation } from "@angular/core";
import { Connection } from "@connections/shared/connection.model";
import { Dataservice } from "@dataservices/shared/dataservice.model";
import { CardAction, CardConfig, ListConfig } from "patternfly-ng";
@Component({
encapsulation: ViewEncapsulation.None,
selector: "app-dataservice-card-component",
templateUrl: "./dataservice-card.component.html",
styleUrls: ["./dataservice-card.component.css"]
})
export class DataserviceCardComponent implements OnInit {
public static readonly activateDataserviceEvent = "activate";
public static readonly deleteDataserviceEvent = "delete";
public static readonly editDataserviceEvent = "edit";
public static readonly publishDataserviceEvent = "publish";
public static readonly quickLookDataserviceEvent = "quickLook";
public static readonly testDataserviceEvent = "test";
public readonly activateEvent = DataserviceCardComponent.activateDataserviceEvent;
public readonly deleteEvent = DataserviceCardComponent.deleteDataserviceEvent;
public readonly editEvent = DataserviceCardComponent.editDataserviceEvent;
public readonly publishEvent = DataserviceCardComponent.publishDataserviceEvent;
public readonly quickLookEvent = DataserviceCardComponent.quickLookDataserviceEvent;
public readonly testEvent = DataserviceCardComponent.testDataserviceEvent;
@Input() public dataservice: Dataservice;
@Input() public selectedDataservices: Dataservice[];
@Output() public cardEvent: EventEmitter< {} > = new EventEmitter< {} >();
@Output() public selectEvent: EventEmitter< Dataservice > = new EventEmitter< Dataservice >();
public cardConfig: CardConfig;
public listConfig: ListConfig;
public showDetails = false;
constructor() {
// nothing to do
}
/**
* @returns {string} the dataservice description
*/
public get description(): string {
return this.dataservice.getDescription();
}
/**
* @param {string} view the view whose connections are being requested
* @returns {Connection[]} the connections of the dataservice represented by this card
*/
public getConnections( view: string ): Connection[] {
// TODO rewrite when REST functionality has been implemented
const result: Connection[] = [];
const c1 = new Connection();
c1.setId( "ConnectionOne" );
result.push( c1 );
const c2 = new Connection();
c2.setId( "ConnectionTwo" );
result.push( c2 );
const c3 = new Connection();
c3.setId( "ConnectionThree" );
result.push( c3 );
return result;
}
/**
* @param {Dataservice} ds the dataservice whose views are being requested
* @returns {string[]} the names of the views
*/
public getViews( ds: Dataservice ): string[] {
const result: string[] = [];
for (const viewName of ds.getServiceViewNames()) {
result.push(viewName);
}
return result;
}
/**
* @returns {boolean} `true` if the dataservice represented by this card is selected
*/
public isSelected(): boolean {
return this.selectedDataservices.indexOf( this.dataservice ) !== -1;
}
public ngOnInit(): void {
this.cardConfig = {
action: {
id: "showDetails",
hypertext: this.showDetailsTitle,
iconStyleClass: "fa fa-info-circle"
},
titleBorder: true,
noPadding: true,
topBorder: false
} as CardConfig;
this.listConfig = {
dblClick: false,
multiSelect: false,
selectItems: false,
showCheckbox: false,
useExpandItems: false
} as ListConfig;
}
/**
* An event handler for when a toolbar action is invoked.
* @param {string} type the type of event being processed
*/
public onClick( type: string ): void {
this.cardEvent.emit( { eventType: type, dataserviceName: this.dataservice.getId() } );
}
/**
* An event handler for when the card is clicked.
*/
public onSelect(): void {
this.selectEvent.emit( this.dataservice );
}
/**
* An event handler for footer action link.
* @param {CardAction} $event the event being processed
*/
public onShowDetails( $event: CardAction ): void {
this.showDetails = !this.showDetails;
$event.hypertext = this.showDetailsTitle;
}
/**
* @returns {string} the footer details action text
*/
public get showDetailsTitle(): string {
return this.showDetails ? "Hide Details" : "Show Details";
}
}