This repository has been archived by the owner on Nov 22, 2019. It is now read-only.
/
connection-card.component.ts
164 lines (142 loc) · 5 KB
/
connection-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
162
163
164
/**
* @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, DoCheck, EventEmitter, Input, OnInit, Output, ViewEncapsulation } from "@angular/core";
import { Connection } from "@connections/shared/connection.model";
import { ConnectionsConstants } from "@connections/shared/connections-constants";
import { LoggerService } from "@core/logger.service";
import { Action, ActionConfig, CardAction, CardConfig, ListConfig } from "patternfly-ng";
@Component({
encapsulation: ViewEncapsulation.None,
selector: "app-connection-card",
templateUrl: "./connection-card.component.html",
styleUrls: ["./connection-card.component.css"]
})
export class ConnectionCardComponent implements DoCheck, OnInit {
public static readonly deleteConnectionEvent = "delete";
public static readonly editConnectionEvent = "edit";
public static readonly pingConnectionEvent = "ping";
public readonly editEvent = ConnectionCardComponent.editConnectionEvent;
public readonly pingEvent = ConnectionCardComponent.pingConnectionEvent;
@Input() public connection: Connection;
@Input() public selectedConnections: Connection[];
@Output() public cardEvent: EventEmitter< {} > = new EventEmitter< {} >();
@Output() public selectEvent: EventEmitter< Connection > = new EventEmitter< Connection >();
public actionConfig: ActionConfig;
public cardConfig: CardConfig;
public listConfig: ListConfig;
public showDetails = false;
private readonly deleteActionId = "delete";
private logger: LoggerService;
constructor( logger: LoggerService ) {
this.logger = logger;
}
private get detailsIconStyle(): string {
return this.showDetails ? "fa fa-close card-footer-action-icon" : "fa fa-angle-right card-footer-action-icon";
}
/**
* Event handler for when a toolbar kebab action is clicked.
* @param {Action} action the action that was selected.
*/
public handleAction( action: Action ): void {
if ( action.id === this.deleteActionId ) {
this.onClick( ConnectionCardComponent.deleteConnectionEvent );
} else {
this.logger.error( "Action '" + action.id + "' not handled." );
}
}
/**
* @returns {boolean} `true` if the connection represented by this card is selected
*/
public isSelected(): boolean {
return this.selectedConnections.indexOf( this.connection ) !== -1;
}
public ngDoCheck(): void {
this.cardConfig.action.iconStyleClass = this.detailsIconStyle;
}
/**
* Initializes the ActionConfig, CardConfig, and ListConfig.
*/
public ngOnInit(): void {
this.actionConfig = {
primaryActions: [
],
moreActions: [
{
id: this.deleteActionId,
title: "Delete",
tooltip: "Delete the connection"
}
]
} as ActionConfig;
this.cardConfig = {
action: {
id: "showDetails",
hypertext: this.showDetailsTitle,
iconStyleClass: this.detailsIconStyle
},
titleBorder: true,
noPadding: true,
topBorder: false
} as CardConfig;
this.listConfig = {
dblClick: false,
multiSelect: false,
selectItems: false,
selectedItems: this.selectedConnections,
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, connectionName: this.connection.getId() } );
}
/**
* An event handler for when the card is clicked.
*/
public onSelect(): void {
this.selectEvent.emit( this.connection );
}
/**
* 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 properties of a connection
*/
public get properties(): string[][] {
const props = [
[ ConnectionsConstants.jndiNamePropertyLabel, this.connection.getJndiName() ],
[ ConnectionsConstants.driverNamePropertyLabel, this.connection.getDriverName() ],
[ ConnectionsConstants.serviceCatalogSourceNameLabel, this.connection.getServiceCatalogSourceName() ],
];
return props;
}
/**
* @returns {string} the footer details action text
*/
public get showDetailsTitle(): string {
return this.showDetails ? "Less" : "More";
}
}