update files

This commit is contained in:
nuintun 2015-11-23 15:23:34 +08:00
parent 469ebd9744
commit ea69932db8
6 changed files with 105 additions and 49 deletions

View File

@ -13,15 +13,18 @@ require('../components/app-nav');
require('../components/app-main'); require('../components/app-main');
window.addEventListener('DOMContentLoaded', function (){ window.addEventListener('DOMContentLoaded', function (){
var app;
function normalize(configure){ function normalize(configure){
return JSON.parse(JSON.stringify(configure)); return JSON.parse(JSON.stringify(configure));
} }
var app = new Vue({ function init(configure){
app = new Vue({
el: '#app', el: '#app',
data: { data: {
activeIndex: 0, activeIndex: 0,
configure: { projects: [] } configure: configure
}, },
computed: { computed: {
uniqueProjects: function (){ uniqueProjects: function (){
@ -43,13 +46,20 @@ window.addEventListener('DOMContentLoaded', function (){
} }
} }
}); });
}
ipc.on('app-configure', function (event, command, configure){ ipc.on('app-configure', function (event, command, configure){
switch (command) { switch (command) {
case 'refresh': case 'refresh':
if (app) {
app.activeIndex = 0; app.activeIndex = 0;
configure.projects = configure.projects || []; configure.projects = configure.projects || [];
app.configure = configure; app.configure = configure;
app.$broadcast('configure-refresh');
} else {
init(configure);
}
break; break;
} }
}); });

View File

@ -1,4 +1,4 @@
<project-configure :project.sync="project"></project-configure> <project-configure :project="project" :unique-projects.sync="uniqueProjects"></project-configure>
<div class="ui-project-stage fn-hide"> <div class="ui-project-stage fn-hide">
<div class="ui-control-bar fn-clear"> <div class="ui-control-bar fn-clear">
<div class="ui-control-operate fn-left"> <div class="ui-control-operate fn-left">

View File

@ -28,14 +28,12 @@ module.exports = Vue.component('app-main', {
required: true required: true
} }
}, },
data: function (){
return {};
},
computed: { computed: {
project: function (){ project: function (){
var project = this.projects[this.activeIndex] || { var project = this.projects[this.activeIndex];
name: '',
path: '',
env: [],
command: []
};
if (!project.env) { if (!project.env) {
project.env = []; project.env = [];
@ -45,7 +43,19 @@ module.exports = Vue.component('app-main', {
project.command = []; project.command = [];
} }
return project; return JSON.parse(JSON.stringify(project));
}
},
methods: {
remove: function (){
this.projects.splice(this.activeIndex, 1);
this.$dispatch('save-configure');
}
},
events: {
edit: function (project){
this.projects.$set(this.activeIndex, project);
this.$dispatch('save-configure');
} }
} }
}); });

View File

@ -56,19 +56,22 @@ module.exports = Vue.component('dynamic-item', {
this.value = this.value.trim(); this.value = this.value.trim();
// name error // name error
if (!this.name) { if (this.name) {
this.nameError = '不能为空'; if (this.uniqueItems[this.name]) {
} else if (this.uniqueItems[this.name]) {
this.nameError = ' ' + this.name + ' 已存在'; this.nameError = ' ' + this.name + ' 已存在';
} else { } else {
this.nameError = ''; this.nameError = '';
} }
} else {
this.nameError = '不能为空';
}
// value error // value error
if (!this.value) { if (this.value) {
this.valueError = '不能为空';
} else {
this.valueError = ''; this.valueError = '';
} else {
this.valueError = '不能为空';
} }
// add item // add item

View File

@ -6,7 +6,6 @@
var fs = require('fs'); var fs = require('fs');
var path = require('path'); var path = require('path');
var ipc = require('ipc-renderer');
var Vue = require('../../vue/vue'); var Vue = require('../../vue/vue');
require('../project-base'); require('../project-base');
@ -16,11 +15,27 @@ module.exports = Vue.component('project-configure', {
template: fs.readFileSync(path.join(__dirname, 'project-configure.html')).toString(), template: fs.readFileSync(path.join(__dirname, 'project-configure.html')).toString(),
props: { props: {
project: { project: {
type: Object,
required: true
},
uniqueProjects: {
type: Object, type: Object,
twoWay: true, twoWay: true,
required: true required: true
} }
}, },
data: function (){
return {
nameError: '',
pathError: '',
submitError: ''
}
},
computed: {
projectClone: function (){
return JSON.parse(JSON.stringify(this.project));
}
},
methods: { methods: {
focus: function (event){ focus: function (event){
if (event.target.type === 'text') { if (event.target.type === 'text') {
@ -28,9 +43,26 @@ module.exports = Vue.component('project-configure', {
} }
}, },
edit: function (){ edit: function (){
this.$broadcast('submit'); var name = this.projectClone.name;
var originName = this.project.name;
console.log(this.project); if (this.projectClone.name && this.projectClone.path) {
if (name !== originName && this.uniqueProjects[name]) {
this.submitError = '项目已存在';
} else {
// clean error
this.submitError = '';
// send message
this.$dispatch('edit', this.projectClone);
}
}
}
},
events: {
'configure-refresh': function (){
this.submitError = '';
this.$broadcast('clean-error');
} }
} }
}); });

View File

@ -7,15 +7,16 @@
</div> </div>
</div> </div>
<div class="ui-project-configure"> <div class="ui-project-configure">
<div v-show="submitError" class="ui-submit-tips">{{ submitError }}</div>
<ul> <ul>
<li is="project-base" :name.sync="project.name" :path.sync="project.path"></li> <li is="project-base" :name.sync="projectClone.name" :path.sync="projectClone.path"></li>
<li class="ui-sub-item"> <li class="ui-sub-item">
<label>环境变量:</label> <label>环境变量:</label>
<dynamic-item name-label="变量名" value-label="变量值" :items.sync="project.env"></dynamic-item> <dynamic-item name-label="变量名" value-label="变量值" :items.sync="projectClone.env"></dynamic-item>
</li> </li>
<li id="add-cmd" class="ui-sub-item"> <li id="add-cmd" class="ui-sub-item">
<label>项目命令:</label> <label>项目命令:</label>
<dynamic-item name-label="名称" value-label="命令" :items.sync="project.command"></dynamic-item> <dynamic-item name-label="名称" value-label="命令" :items.sync="projectClone.command"></dynamic-item>
</li> </li>
</ul> </ul>
</div> </div>