Skip to content

Commit c361fac

Browse files
Added BayTypical to menu on frontend.
Added Sitipe Service URL CoMPAS Setting
1 parent 385f31c commit c361fac

File tree

7 files changed

+306
-39
lines changed

7 files changed

+306
-39
lines changed

index.html

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,11 @@
1414
<base href="/">
1515

1616
<!-- Original URL from Google: https://fonts.googleapis.com/css2?family=Roboto+Mono:wght@300&family=Roboto:wght@300;400;500&display=swap -->
17-
<link href="public/google/fonts/roboto-v27.css" rel="stylesheet">
18-
<link href="public/google/fonts/roboto-mono-v13.css" rel="stylesheet">
17+
<link href="/public/google/fonts/roboto-v27.css" rel="stylesheet">
18+
<link href="/public/google/fonts/roboto-mono-v13.css" rel="stylesheet">
1919
<!-- Original URL from Google: https://fonts.googleapis.com/css?family=Material+Icons+Outlined&display=block -->
20-
<link href="public/google/icons/material-icons-outlined.css" rel="stylesheet">
21-
<link href="public/css/normalize.css" rel="stylesheet">
20+
<link href="/public/google/icons/material-icons-outlined.css" rel="stylesheet">
21+
<link href="/public/css/normalize.css" rel="stylesheet">
2222
<link rel="manifest" href="manifest.json" crossorigin="use-credentials">
2323
<link rel="icon" type="image/png" sizes="16x16" href="public/favicon-16x16.png">
2424
<link rel="icon" type="image/png" sizes="32x32" href="public/favicon-32x32.png">

public/js/plugins.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,7 @@ export const officialPlugins = [
323323
{
324324
name: 'Sitipe',
325325
src: '/src/editors/Sitipe.js',
326-
icon: 'conveyor_belt',
326+
icon: 'precision_manufacturing',
327327
default: true,
328328
kind: 'editor',
329329
},

src/compas/CompasSettings.ts

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ export type CompasSettingsRecord = {
2020
sclValidatorServiceUrl: string;
2121
cimMappingServiceUrl: string;
2222
sclAutoAlignmentServiceUrl: string;
23+
sitipeServiceUrl: string;
2324
useWebsockets: 'on' | 'off';
2425
};
2526

@@ -34,6 +35,7 @@ export function CompasSettings() {
3435
sclAutoAlignmentServiceUrl: this.getCompasSetting(
3536
'sclAutoAlignmentServiceUrl'
3637
),
38+
sitipeServiceUrl: this.getCompasSetting('sitipeServiceUrl'),
3739
useWebsockets: this.getCompasSetting('useWebsockets'),
3840
};
3941
},
@@ -44,6 +46,7 @@ export function CompasSettings() {
4446
sclValidatorServiceUrl: '/compas-scl-validator',
4547
cimMappingServiceUrl: '/compas-cim-mapping',
4648
sclAutoAlignmentServiceUrl: '/compas-scl-auto-alignment',
49+
sitipeServiceUrl: '/compas-sitipe-service',
4750
useWebsockets: 'on',
4851
};
4952
},
@@ -106,6 +109,12 @@ export class CompasSettingsElement extends LitElement {
106109
);
107110
}
108111

112+
getSitipeServiceUrlField(): TextFieldBase {
113+
return <TextFieldBase>(
114+
this.shadowRoot!.querySelector('mwc-textfield[id="sitipeServiceUrl"]')
115+
);
116+
}
117+
109118
getUseWebsockets(): Switch {
110119
return <Switch>(
111120
this.shadowRoot!.querySelector('mwc-switch[id="useWebsockets"]')
@@ -117,7 +126,8 @@ export class CompasSettingsElement extends LitElement {
117126
this.getSclDataServiceUrlField().checkValidity() &&
118127
this.getSclValidatorServiceUrlField().checkValidity() &&
119128
this.getCimMappingServiceUrlField().checkValidity() &&
120-
this.getSclAutoAlignmentServiceUrlField().checkValidity()
129+
this.getSclAutoAlignmentServiceUrlField().checkValidity() &&
130+
this.getSitipeServiceUrlField().checkValidity()
121131
);
122132
}
123133

@@ -143,6 +153,10 @@ export class CompasSettingsElement extends LitElement {
143153
'sclAutoAlignmentServiceUrl',
144154
this.getSclAutoAlignmentServiceUrlField().value
145155
);
156+
CompasSettings().setCompasSetting(
157+
'sitipeServiceUrl',
158+
this.getSitipeServiceUrlField().value
159+
);
146160
CompasSettings().setCompasSetting(
147161
'useWebsockets',
148162
this.getUseWebsockets().checked ? 'on' : 'off'
@@ -193,6 +207,13 @@ export class CompasSettingsElement extends LitElement {
193207
required
194208
>
195209
</mwc-textfield>
210+
<mwc-textfield
211+
id="sitipeServiceUrl"
212+
label="${translate('compas.settings.sitipeServiceUrl')}"
213+
value="${this.compasSettings.sitipeServiceUrl}"
214+
required
215+
>
216+
</mwc-textfield>
196217
<mwc-formfield label="${translate('compas.settings.useWebsockets')}">
197218
<mwc-switch
198219
id="useWebsockets"

src/editors/sitipe/sitipe-bay.ts

Lines changed: 166 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,166 @@
1+
import {
2+
customElement,
3+
html,
4+
LitElement,
5+
property,
6+
query,
7+
state,
8+
TemplateResult,
9+
} from 'lit-element';
10+
11+
import { Menu } from '@material/mwc-menu';
12+
13+
import '@material/mwc-menu';
14+
import '@material/mwc-list';
15+
import '@material/mwc-icon';
16+
import '@material/mwc-icon-button';
17+
18+
import { IconButton } from '@material/mwc-icon-button';
19+
20+
import { Create, createElement, newActionEvent } from '../../foundation.js';
21+
22+
import '../../action-pane.js';
23+
import '../../action-icon.js';
24+
25+
import {
26+
SIEMENS_SITIPE_IED_REF,
27+
SIEMENS_SITIPE_BAY_TEMPLATE,
28+
} from './foundation.js';
29+
30+
import {
31+
BayTypical,
32+
getBayTypicalComponents,
33+
getImportedBTComponentData,
34+
getImportedBTComponents,
35+
} from './sitipe-service.js';
36+
37+
/** [[`Sitipe`]] plugin subeditor for editing `Sitipe` configuration. */
38+
@customElement('sitipe-bay')
39+
export class SitipeBay extends LitElement {
40+
/** The document being edited as provided to editor by [[`Sitipe`]]. */
41+
@property({ attribute: false })
42+
doc!: XMLDocument;
43+
/** The edited `Element`, a common property of all Sitipe subeditors. */
44+
@property({ attribute: false })
45+
bay!: Element;
46+
47+
@property()
48+
bayTypicals: BayTypical[] = [];
49+
50+
@state()
51+
loading: boolean = false;
52+
53+
@state()
54+
bayHeader(): string {
55+
const name = this.bay.getAttribute('name') ?? '';
56+
const desc = this.bay.getAttribute('desc');
57+
58+
return `${name} ${desc ? `(${desc})` : ''}`;
59+
}
60+
61+
@query('mwc-menu')
62+
menu?: Menu;
63+
64+
@query('mwc-icon-button[icon="playlist_add"]')
65+
iconButton?: IconButton;
66+
67+
updated(): void {
68+
if (this.menu && this.iconButton) {
69+
this.menu!.anchor = <HTMLElement>this.iconButton!;
70+
}
71+
}
72+
73+
get bayTypicalTemplate(): string {
74+
return (
75+
this.bay.querySelector(`Private[type="${SIEMENS_SITIPE_BAY_TEMPLATE}"]`)
76+
?.textContent ?? ''
77+
);
78+
}
79+
80+
private renderIEDs(): TemplateResult {
81+
return html`
82+
<div>
83+
${Array.from(
84+
this.bay.querySelectorAll(
85+
`Private[type="${SIEMENS_SITIPE_IED_REF}"]` ?? []
86+
)
87+
).map(
88+
iedTemplate =>
89+
html`<action-icon
90+
.label=${iedTemplate.textContent
91+
? `${iedTemplate.textContent} (${this.bayTypicalTemplate})`
92+
: ''}
93+
icon="developer_board"
94+
></action-icon>`
95+
)}
96+
</div>
97+
`;
98+
}
99+
100+
protected renderMenu(): TemplateResult {
101+
return html`<mwc-menu
102+
class="actions-menu"
103+
corner="BOTTOM_RIGHT"
104+
menuCorner="END"
105+
>
106+
${this.bayTypicals.map(bayTypical => {
107+
return html`<mwc-list-item
108+
@click=${() => this.handleSelected(bayTypical)}
109+
.disabled=${this.isDisabled(bayTypical)}
110+
>${bayTypical.name}</mwc-list-item
111+
>`;
112+
})}
113+
</mwc-menu>`;
114+
}
115+
116+
render(): TemplateResult {
117+
return html`<action-pane label="${this.bayHeader()}">
118+
<abbr slot="action" title="Add" style="position:relative;">
119+
<mwc-icon-button
120+
icon="playlist_add"
121+
@click="${() => {
122+
this.menu!.open = true;
123+
}}"
124+
></mwc-icon-button>
125+
${this.renderMenu()}
126+
</abbr>
127+
${this.renderIEDs()}</action-pane
128+
>`;
129+
}
130+
131+
private isDisabled(bayTypical: BayTypical): boolean {
132+
return bayTypical.name === this.bayTypicalTemplate;
133+
}
134+
135+
private handleSelected(bayTypical: BayTypical) {
136+
const bayTypicalElement: Element = createElement(this.doc, 'Private', {
137+
type: SIEMENS_SITIPE_BAY_TEMPLATE,
138+
});
139+
140+
bayTypicalElement.textContent = bayTypical.name;
141+
142+
const action: Create = {
143+
new: {
144+
parent: this.bay,
145+
element: bayTypicalElement,
146+
},
147+
};
148+
149+
this.dispatchEvent(newActionEvent(action));
150+
151+
getBayTypicalComponents(bayTypical.accessId).then(btComponents => {
152+
btComponents.forEach(btComponent => {
153+
getImportedBTComponents(btComponent.accessId).then(
154+
importedBtComponents => {
155+
importedBtComponents.forEach(imported => {
156+
getImportedBTComponentData(imported.id).then(data => {
157+
console.log('data');
158+
console.log(data);
159+
});
160+
});
161+
}
162+
);
163+
});
164+
});
165+
}
166+
}
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
import { handleError } from '../../compas-services/foundation.js';
2+
import { CompasSettings } from '../../compas/CompasSettings.js';
3+
4+
export interface BayTypical {
5+
id: string;
6+
accessId: string;
7+
name: string;
8+
version: string;
9+
description: string;
10+
released: number;
11+
lockedBy: string;
12+
lockedOn: number;
13+
modifiedOn: number;
14+
smrFile: string;
15+
contentVersion: string;
16+
referenceAccessId: string;
17+
}
18+
19+
export interface BTComponent {
20+
id: number;
21+
name: string;
22+
typicalAccessId: string;
23+
importedOn: number;
24+
toolName: string;
25+
toolVersion: string;
26+
hasIecInformation: number;
27+
componentGuid: string;
28+
accessId: string;
29+
language: string;
30+
iniVersion: number;
31+
referenceAccessId: string;
32+
}
33+
34+
export interface ImportedBTComponent {
35+
id: number;
36+
type: string;
37+
contentVersion: string;
38+
componentAccessId: string;
39+
accessId: string;
40+
}
41+
42+
export interface ImportedBTComponentData {
43+
data: string;
44+
}
45+
46+
function getSitipeServiceBaseUrl(): string {
47+
return CompasSettings().compasSettings.sitipeServiceUrl;
48+
}
49+
50+
export function getAssignedBayTypicals(): Promise<BayTypical[]> {
51+
return fetch(`${getSitipeServiceBaseUrl()}/v2/baytypicals`)
52+
.catch(handleError)
53+
.then(res => res.json());
54+
}
55+
56+
export function getBayTypicalComponents(
57+
accessId: string
58+
): Promise<BTComponent[]> {
59+
return fetch(
60+
`${getSitipeServiceBaseUrl()}/v2/baytypicals/${accessId}/components`
61+
)
62+
.catch(handleError)
63+
.then(res => res.json());
64+
}
65+
66+
export function getImportedBTComponents(
67+
accessId: string
68+
): Promise<ImportedBTComponent[]> {
69+
return fetch(
70+
`${getSitipeServiceBaseUrl()}/v2/btcomponents/${accessId}/imported`
71+
)
72+
.catch(handleError)
73+
.then(res => res.json());
74+
}
75+
76+
export function getImportedBTComponentData(
77+
id: number
78+
): Promise<ImportedBTComponentData> {
79+
return fetch(`${getSitipeServiceBaseUrl()}/v2/btcomponents/imported/${id}`)
80+
.catch(handleError)
81+
.then(res => res.json());
82+
}

0 commit comments

Comments
 (0)