This repository has been archived by the owner on Jun 29, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfiguretagspace.js
152 lines (151 loc) · 6.54 KB
/
configuretagspace.js
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
const app = require('electron').remote;
const ipcRenderer = require('electron').ipcRenderer;
const fs = require('fs');
const path = require('path');
const imageSize = require('image-size');
const fallbackRef = (obj, key, fallback) => Object.prototype.hasOwnProperty.call(obj, key) ? obj[key] : fallback;
let config = {};
if (fs.existsSync('config.json')) {
config = JSON.parse(fs.readFileSync('config.json'));
}
const creationdir = ipcRenderer.sendSync('getValue', 'creationdir');
// eslint-disable-next-line no-new
new Vue({
el: '#vue-container',
data: {
tagList: fallbackRef(config, 'defaultTags', [['Favorite', '#fed330'], ['Low-Quality', '#26de81'], ['Important', '#fd9644']]),
propList: fallbackRef(config, 'defaultProps', [['Description', 'String']]),
tagspaceTitle: '',
tagspaceDescription: '',
tagviewerData: {}
},
components: {
'listed-tag': {
props: {
name: String,
color: { validator: string => ((/^#([\dabcdef]{3}|[\dabcdef]{6})$/).test(string)) },
ckey: Number
},
template: '<li><label style="padding-left:0;" :for="nameInputId">Name:</label><input type="text" v-model.lazy="localName" :id="nameInputId" required class="name-input"><label :for="colorInputId">Color:</label><input required type="color" v-model.lazy="localColor" :id="colorInputId" class="color-input"><button type="button" @click="removeTag"><i class="material-icons">remove</i></button></li>',
data: function () {
return {
localName: this.name,
localColor: this.color
};
},
computed: {
nameInputId: function () {
return `tagName${this.ckey}`;
},
colorInputId: function () {
return `tagColor${this.ckey}`;
}
},
watch: {
localName: function () {
this.$emit('update-name', this.ckey, this.localName);
},
localColor: function () {
this.$emit('update-color', this.ckey, this.localColor);
},
name: function (val) {
this.localName = val;
},
color: function (val) {
this.localColor = val;
}
},
methods: {
removeTag: function () {
this.$emit('remove-tag', this.ckey);
}
}
},
'listed-prop': {
props: {
name: String,
type: {
validator: function (string) {
return ['String', 'Number', 'Boolean', 'Size', 'Resolution'].indexOf(string) !== -1;
}
},
ckey: Number,
disabled: Boolean
},
template: '<li><label style="padding-left:0" v-bind:for="nameInputId">Name:</label><input type="text" v-model.lazy="localName" v-bind:disabled="disabled" v-bind:id="nameInputId" required class="name-input"><label v-bind:for="typeInputId">Type:</label><select required v-model.lazy="localType" v-bind:disabled="disabled" :id="typeInputId" class="type-input"><option value="String">String</option><option value="Number">Number</option><option value="Boolean">Boolean (yes or no)</option></select><button type="button" @click="removeProp" :style="{visibility:disabled?\'hidden\':\'visible\'}" :disabled="disabled"><i class="material-icons">remove</i></button></li>',
data: function () {
return {
localName: this.name,
localType: this.type
};
},
computed: {
nameInputId: function () {
return `propName${this.ckey}`;
},
typeInputId: function () {
return `propType${this.ckey}`;
}
},
watch: {
localName: function (newValue) {
this.$emit('update-name', this.ckey, newValue);
},
localType: function (newValue) {
this.$emit('update-type', this.ckey, newValue);
},
name: function (newValue) {
this.localName = newValue;
},
type: function (newValue) {
this.localType = newValue;
}
},
methods: {
removeProp: function () {
this.$emit('remove-prop', this.ckey);
}
}
}
},
methods: {
updateTagName: function (index, newValue) { this.tagList[index][0] = newValue; },
updateTagColor: function (index, newValue) { this.tagList[index][1] = newValue; },
removeTag: function (index) { this.$delete(this.tagList, index); },
addTag: function () { this.tagList.push(['', '#000000']); setTimeout(() => document.querySelector('#tag-list > li:last-of-type > .name-input').focus(), 50); },
updatePropName: function (index, newValue) { this.propList[index][0] = newValue; },
updatePropType: function (index, newValue) { this.propList[index][1] = newValue; },
removeProp: function (index) { this.$delete(this.propList, index); },
addProp: function () { this.propList.push(['', 'String']); setTimeout(() => document.querySelector('#prop-list > li:last-of-type > .name-input').focus(), 50); },
createTagspace: function () {
this.tagviewerData = { title: this.tagspaceTitle, description: this.tagspaceDescription, tagList: this.tagList, deletedTags: [], propList: this.propList, files: [] };
this.addImages();
},
addImages: function () {
const fileList = app.dialog.showOpenDialogSync(app.getCurrentWindow(), {
title: 'Add Media',
filters: [{ name: 'Images', extensions: ['gif', 'png', 'jpg', 'jpeg', 'svg', 'webp'] }, { name: 'Videos', extensions: ['.flac', '.mp4', '.webm', '.wav'] }, { name: 'All Media', extensions: ['gif', 'png', 'jpg', 'jpeg', 'svg', 'webp', '.flac', '.mp4', '.webm', '.wav'] }],
properties: ['openFile', 'multiSelections'],
message: "Cancel if you don't want to add media at this stage."
});
if (typeof fileList !== 'undefined') {
for (const i in fileList) {
const file = fileList[i];
fs.copyFileSync(file, path.join(creationdir, i + path.extname(file))); // should this be synchronous?
this.tagviewerData.files[i] = {
_index: i,
_path: i + path.extname(file),
_origBasename: path.basename(file),
tags: [],
props: {},
title: path.parse(file).name,
size: fs.statSync(file).size,
resolution: ((['.flac', '.mp4', '.webm', '.wav'].includes(path.extname(file))) ? [-1, -1] : (a => [a.width, a.height])(imageSize(file)))
};
}
}
this.tagviewerData.currentIndex = (typeof fileList !== 'undefined') ? fileList.length : 0;
fs.writeFile(path.join(creationdir, 'tagviewer.json'), JSON.stringify(this.tagviewerData, null, 2), () => ipcRenderer.send('doneCreating'));
}
}
});