Skip to content

Commit

Permalink
add scripts links
Browse files Browse the repository at this point in the history
  • Loading branch information
iwate committed Feb 24, 2020
1 parent 4901475 commit 32a0e1f
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/Aiplugs.PoshApp/Views/Shared/Pages/List.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@
<transition name="slide-x-reverse-transition">
<detail-page :script="detailScriptId" :input="detailInput" v-if="detailScriptId" v-on:close="detailScriptId=null"></detail-page>
</transition>
<v-btn color="primary" fab dark style="position: absolute; bottom: 8px; right: 8px;" v-on:click="gotoEditor">
<v-icon>mdi-xml</v-icon>
</v-btn>
</div>
</template>
<script type="module">
Expand Down Expand Up @@ -140,6 +143,15 @@
const clixml = item.$clixml;
this.detailInput = clixml;
this.detailScriptId = this.detailId;
},
gotoEditor() {
if (this.detailId) {
const [repo, id] = this.detailId.split(':');
this.$router.push(`/scripts/${repo}/${id}`)
}
else {
this.$router.push(`/scripts/${this.$route.params.repo}/${this.$route.params.id}`)
}
}
},
mounted() {
Expand Down
45 changes: 45 additions & 0 deletions src/Aiplugs.PoshApp/Views/Shared/Scripts/Index.cshtml
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
<template id="scripts-component">
<div style="position: absolute; width: 100%; height: 100%;" v-resize="handleResize">
<div>
<v-btn text v-on:click="save" :disabled="!editor">Save</v-btn>
<v-btn text v-on:click="gotoApp">Goto App</v-btn>
</div>
<div ref="editor" class="fill-height"></div>
</div>
</template>
Expand Down Expand Up @@ -68,6 +72,47 @@
if (this.editor) {
this.editor.layout();
}
},
async save() {
const value = this.editor.getModel().getValue();
await this.saveScriptContent(this.$route.params.repo, this.$route.params.id, value);
this.toast({
text: "Saved",
color: "success",
top: true,
right: true
});
},
gotoListFromDetail(repo, id) {
const page = this.$store.getters['scripts/findPageByDetail'](repo, id);
if (page) {
this.$router.push(`/${page.type.toLowerCase()}/${page.repository}/${page.id}`);
}
},
gotoPageFromAction(repo, id) {
const page = this.$store.getters['scripts/findPageByAction'](repo, id);
if (page) {
if (page.type === 'Detail') {
this.gotoListFromDetail(page.repository, page.id);
}
else {
this.$router.push(`/${page.type.toLowerCase()}/${page.repository}/${page.id}`);
}
}
},
gotoApp() {
const { repo, id } = this.$route.params;
const script = this.$store.getters['scripts/find'](repo, id);
if (['List', 'Singleton'].includes(script.type)) {
this.$router.push(`/${script.type.toLowerCase()}/${repo}/${id}`);
}
else if (script.type === 'Detail') {
this.gotoListFromDetail(repo, id);
}
else if (script.type === 'Action') {
this.gotoPageFromAction(repo, id);
}
}
},
mounted() {
Expand Down
16 changes: 16 additions & 0 deletions src/Aiplugs.PoshApp/wwwroot/js/store/scripts.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,22 @@ export default {
}
return `${repo}:${id}`;
};
},
findPageByDetail(state) {
return (repo, id) => {
const key = `${repo}:${id}`;
const domestics = state.metadata[repo].filter(s => s.type === 'List' && s.detail === id);
const others = Object.keys(state.metadata).map(key => state.metadata[key]).flat().filter(s => s.type === 'List' && s.detail === key);
return domestics.concat(others)[0];
};
},
findPageByAction(state) {
return (repo, id) => {
const key = `${repo}:${id}`;
const domestics = state.metadata[repo].filter(s => s.actions && s.actions.includes(id));
const others = Object.keys(state.metadata).map(key => state.metadata[key]).flat().filter(s => s.actions && s.actions.includes(key));
return domestics.concat(others)[0];
};
}
},
mutations: {
Expand Down

0 comments on commit 32a0e1f

Please sign in to comment.