Skip to content

Commit 32d06db

Browse files
author
Rob Tjalma
authored
Merge pull request #146 from com-pas/save-as-plugin
Added plugin to save project with a new name
2 parents a8bb080 + 62fe9f1 commit 32d06db

File tree

3 files changed

+93
-1
lines changed

3 files changed

+93
-1
lines changed

public/js/plugins.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,15 @@ export const officialPlugins = [
100100
requireDoc: true,
101101
position: 'top'
102102
},
103+
{
104+
name: 'Save project as',
105+
src: '/src/menu/CompasSaveAs.js',
106+
icon: 'save',
107+
default: true,
108+
kind: 'menu',
109+
requireDoc: true,
110+
position: 'top'
111+
},
103112
{
104113
name: 'Validate using OCL',
105114
src: '/src/validators/CompasValidateSchema.js',

src/menu/CompasSaveAs.ts

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
import {html, LitElement} from 'lit-element';
2+
import {get} from "lit-translate";
3+
4+
import {newPendingStateEvent, newWizardEvent, Wizard, WizardInputElement} from '../foundation.js';
5+
6+
import CompasSaveElement from "../compas/CompasSave.js";
7+
import {dispatchEventOnOpenScd} from "../compas/foundation.js";
8+
9+
import "../compas/CompasSave.js";
10+
11+
export default class CompasSaveMenuPlugin extends LitElement {
12+
doc!: XMLDocument;
13+
docName!: string;
14+
15+
private saveAsToCompasWizard(): Wizard {
16+
function saveToCompas() {
17+
return function (inputs: WizardInputElement[], wizard: Element) {
18+
const compasSave = <CompasSaveElement>wizard.shadowRoot!.querySelector('compas-save')
19+
if (!compasSave.valid()) {
20+
return [];
21+
}
22+
23+
dispatchEventOnOpenScd(newPendingStateEvent(compasSave.saveToCompas()));
24+
return [];
25+
};
26+
}
27+
28+
return [
29+
{
30+
title: get('compas.save.title'),
31+
primary: {
32+
icon: 'save',
33+
label: get('save'),
34+
action: saveToCompas(),
35+
},
36+
content: [
37+
html `<compas-save .doc="${this.doc}" .docName="${this.docName}">
38+
</compas-save>`
39+
],
40+
},
41+
];
42+
}
43+
44+
async run(): Promise<void> {
45+
this.dispatchEvent(newWizardEvent(this.saveAsToCompasWizard()));
46+
}
47+
}
48+
49+

test/integration/__snapshots__/open-scd.test.snap.js

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/* @web/test-runner snapshot v1 */
22
export const snapshots = {};
33

4-
snapshots["open-scd looks like its snapshot"] =
4+
snapshots["open-scd looks like its snapshot"] =
55
`<mwc-drawer
66
class="mdc-theme--surface"
77
hasheader=""
@@ -87,6 +87,24 @@ snapshots["open-scd looks like its snapshot"] =
8787
<mwc-linear-progress indeterminate="">
8888
</mwc-linear-progress>
8989
</mwc-list-item>
90+
<mwc-list-item
91+
aria-disabled="true"
92+
class="top"
93+
disabled=""
94+
graphic="icon"
95+
iconid="save"
96+
mwc-list-item=""
97+
tabindex="-1"
98+
>
99+
<mwc-icon slot="graphic">
100+
save
101+
</mwc-icon>
102+
<span>
103+
Save project as
104+
</span>
105+
<mwc-linear-progress indeterminate="">
106+
</mwc-linear-progress>
107+
</mwc-list-item>
90108
<li
91109
divider=""
92110
padded=""
@@ -881,6 +899,22 @@ snapshots["open-scd looks like its snapshot"] =
881899
</mwc-icon>
882900
Save project
883901
</mwc-check-list-item>
902+
<mwc-check-list-item
903+
aria-disabled="false"
904+
class="official"
905+
graphic="control"
906+
hasmeta=""
907+
left=""
908+
mwc-list-item=""
909+
selected=""
910+
tabindex="-1"
911+
value="/src/menu/CompasSaveAs.js"
912+
>
913+
<mwc-icon slot="meta">
914+
save
915+
</mwc-icon>
916+
Save project as
917+
</mwc-check-list-item>
884918
<li
885919
divider=""
886920
inset=""

0 commit comments

Comments
 (0)