Skip to content

Commit 64a0bf7

Browse files
committed
Creating Archive functionality.
1 parent cfcf960 commit 64a0bf7

File tree

10 files changed

+423
-317
lines changed

10 files changed

+423
-317
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,4 +91,4 @@
9191
"cordova-plugin-whitelist": {}
9292
}
9393
}
94-
}
94+
}

src/components/note-display.vue

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,27 @@
11
<template lang="pug">
22
v-card
3-
v-toolbar(color="primary", dense)
3+
v-toolbar(:color="(is_archive === true) ? 'secondary' : 'primary'", dense)
44
v-toolbar-title {{ title }}
55
v-spacer
66
v-toolbar-items
7-
v-btn(small, icon, v-if="confidential === true", @click="show_content = !show_content")
8-
v-icon remove_red_eye
9-
v-btn(small, icon, :to="{name: 'edit-note', params: {id: id}}")
10-
v-icon edit
7+
v-tooltip(bottom)
8+
v-btn(small, icon, @click="$store.dispatch('toggleArchive', {_id: id})", slot="activator")
9+
v-icon(v-if="is_archive") inbox
10+
v-icon(v-else) move_to_inbox
11+
span(v-if="is_archive") {{ $t('Unarchive this note') }}
12+
span(v-else) {{ $t('Archive this note') }}
13+
v-tooltip(bottom, v-if="confidential === true")
14+
v-btn(small, icon, @click="show_content = !show_content", slot="activator")
15+
v-icon(v-if="show_content") visibility_off
16+
v-icon(v-else) visibility
17+
span(v-if="show_content") {{ $t('Hide the content of the note') }}
18+
span(v-else) {{ $t('Show the content of the note') }}
19+
v-tooltip(bottom)
20+
v-btn(small, icon, :to="{name: 'edit-note', params: {id: id}}", slot="activator")
21+
v-icon edit
22+
span {{ $t('Edit the note') }}
1123
v-card-text
12-
pre(v-if="confidential !== true || show_content", style="overflow:auto;", v-html="htmlContent")
24+
div(v-if="confidential !== true || show_content", style="overflow:auto;", v-html="htmlContent")
1325
i(v-else) [{{ $t('confidential') }}]
1426
div(v-if="subjects !== undefined", class="text-xs-right")
1527
v-divider(style="margin: 0.5em 0px;")
@@ -25,7 +37,7 @@ const markdownConverter = markdownIt().use(markdownItCheckboxes);
2537
2638
export default {
2739
name: 'note-display',
28-
props: ['id', 'title', 'content', 'confidential', 'subjects'],
40+
props: ['id', 'title', 'content', 'confidential', 'subjects', 'is_archive'],
2941
data() {
3042
return {
3143
show_content: false,

src/components/notes-filter.vue

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
<template lang="pug">
2+
div
3+
v-autocomplete(
4+
v-model="filters.subjects",
5+
:items="availableSubjects",
6+
:label="$t('Filter')",
7+
class="mx-1",
8+
prepend-inner-icon="filter_list",
9+
flat, multiple, dense, chips,
10+
deletable-chips, small-chips,
11+
clearable, solo, hide-no-data,
12+
hide-details)
13+
div(class="mx-1")
14+
v-checkbox(
15+
:label="$t('Display archives')",
16+
v-model="filters.show_archives")
17+
</template>
18+
19+
<script>
20+
export default {
21+
name: 'notes-filter',
22+
prop: ['value'],
23+
data() {
24+
return {
25+
filters: {
26+
subjects: [],
27+
show_archives: false,
28+
},
29+
};
30+
},
31+
watch: {
32+
filters: {
33+
handler(val) {
34+
this.$emit('input', val);
35+
},
36+
deep: true,
37+
},
38+
},
39+
computed: {
40+
availableSubjects() {
41+
let result = ['*' + this.$t('no subject') + '*'];
42+
43+
result = result.concat(Object.keys(this.$store.state.subjects));
44+
45+
return result;
46+
},
47+
},
48+
created() {
49+
// this.$emit('input', this.filters);
50+
}
51+
};
52+
</script>

src/locales/en-US.json

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,5 +57,10 @@
5757
"Please paste your data in the following field and click on the button in the the bottom of the page, in order to load them in this app.": "Please paste your data in the following field and click on the button in the the bottom of the page, in order to load them in this app.",
5858
"The note is not saved, you will lost the changes if your are leaving the page. Please confirm the exit.": "The note is not saved, you will lost the changes if your are leaving the page. Please confirm the exit.",
5959
"no subject": "no subject",
60-
"Preview": "Preview"
60+
"Preview": "Preview",
61+
"Display archives": "Display archives",
62+
"Archive this note": "Archive this note",
63+
"Unarchive this note": "Unarchive this note",
64+
"Show the content of the note": "Show the content of the note",
65+
"Hide the content of the note": "Hide the content of the note"
6166
}

src/locales/fr-FR.json

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,5 +57,10 @@
5757
"Please paste your data in the following field and click on the button in the the bottom of the page, in order to load them in this app.": "Veuillez coller vos données dans le champ suivant et clicker sur le bouton en bas de la page pour les importer dans cette application.",
5858
"The note is not saved, you will lost the changes if your are leaving the page. Please confirm the exit.": "La note n'est pas enregistrée, vous allez perdre les changements si vous quittez la page. Veuillez confirmer que vous souhaitez partir maintenant.",
5959
"no subject": "pas de sujet",
60-
"Preview": "Prévisualisation"
60+
"Preview": "Prévisualisation",
61+
"Display archives": "Afficher les archives",
62+
"Archive this note": "Archiver cette note",
63+
"Unarchive this note": "Désarchiver cette note",
64+
"Show the content of the note": "Afficher le contenu de la note",
65+
"Hide the content of the note": "Cacher le contenu de la note"
6166
}

src/store.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -410,6 +410,30 @@ const store = new Vuex.Store({
410410
console.error('$store.actions.setNotesFilter : payload or payload.value is undefined');
411411
}
412412
},
413+
toggleArchive(context, payload) {
414+
return new Promise((resolve, reject) => {
415+
if(typeof(payload._id) === 'undefined') {
416+
reject('$store.actions.toggleArchive : missing "_id" in payload');
417+
return;
418+
}
419+
420+
let data = cloneDeep(context.state.notes[payload._id]);
421+
if(typeof(data) !== 'undefined') {
422+
423+
if(typeof(data.archived) === 'undefined') {
424+
data.archived = true;
425+
} else {
426+
data.archived = !data.archived;
427+
}
428+
429+
db.put(data)
430+
.then((res) => {
431+
resolve(res);
432+
})
433+
.catch((err) => { reject(err); });
434+
}
435+
});
436+
},
413437
},
414438
});
415439

src/views/ExportData.vue

Lines changed: 34 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -10,31 +10,33 @@ div
1010
v-icon archive
1111
v-toolbar-title {{ $t('Export your data manually') }}
1212
v-card-text
13-
v-autocomplete(
14-
v-model="subjectsFilters",
15-
:items="filters",
16-
:label="$t('Filter')",
17-
class="mb-2 mx-1",
18-
prepend-inner-icon="filter_list",
19-
v-if="notes !== undefined && notes.length > 0",
20-
flat, multiple, dense, chips, deletable-chips, small-chips, clearable, hide-no-data, hide-details)
21-
v-switch(:label="$t('Make it human readable')", v-model="readable")
22-
v-switch(:label="$t('Include confidential notes')", v-model="confidentials")
13+
notes-filter(v-model="filters")
14+
div(class="mx-1")
15+
v-checkbox(:label="$t('Make it human readable')", v-model="readable")
16+
v-checkbox(:label="$t('Include confidential notes')", v-model="show_confidential")
2317
v-alert(type="info", :value="true") {{ $t('In order to save your data, just copy and paste the following data in an text editor (like notepad), and then save it as *.json file.') }}
2418
v-divider(class="my-3")
2519
v-textarea(:label="$t('Your data')", readonly, hide-details, auto-grow, v-model="dbData")
2620
</template>
2721

2822
<script>
23+
import NotesFilter from '@/components/notes-filter.vue';
24+
2925
export default {
3026
name: 'export-data',
3127
data() {
3228
return {
3329
readable: true,
34-
confidentials: true,
35-
subjectsFilters: [],
30+
show_confidential: true,
31+
filters: {
32+
subjects: [],
33+
show_archives: false,
34+
},
3635
};
3736
},
37+
components: {
38+
'notes-filter': NotesFilter,
39+
},
3840
computed: {
3941
notes () {
4042
return Object.keys(this.$store.state.notes).map((key) => {
@@ -46,49 +48,60 @@ export default {
4648
4749
return this.notes.filter((note) => {
4850
51+
const archiveFilter = function() {
52+
if(that.filters.show_archives === true) {
53+
return true;
54+
} else {
55+
return !(note.archived === true);
56+
}
57+
}
58+
4959
const confidentialFilter = function() {
50-
return !(that.confidentials === false && note.confidential === true);
60+
return !(that.show_confidential === false && note.confidential === true);
5161
}
5262
5363
const subjectFilter = function() {
54-
let result = !(that.subjectsFilters.length > 0);
64+
let result = !(that.filters.subjects.length > 0);
5565
5666
if(typeof(note.subjects) !== 'undefined') {
57-
if(that.subjectsFilters.includes('*' + that.$t('no subject') + '*') && note.subjects.length === 0) {
67+
if(that.filters.subjects.includes('*' + that.$t('no subject') + '*') && note.subjects.length === 0) {
5868
result = true;
5969
} else {
6070
for (let i = 0; i < note.subjects.length; i++) {
61-
if(that.subjectsFilters.includes(note.subjects[i])) {
71+
if(that.filters.subjects.includes(note.subjects[i])) {
6272
result = true;
6373
break;
6474
}
6575
}
6676
}
6777
} else {
68-
if(that.subjectsFilters.includes('*' + that.$t('no subject') + '*')) {
78+
if(that.filters.subjects.includes('*' + that.$t('no subject') + '*')) {
6979
result = true;
7080
}
7181
}
7282
7383
return result;
7484
}
7585
76-
return confidentialFilter() && subjectFilter();
86+
return archiveFilter() && confidentialFilter() && subjectFilter();
7787
});
7888
},
7989
dbData() {
8090
return JSON.stringify(
8191
{
8292
notes: {
83-
filters: this.subjectsFilters.map((filter) => { return (filter === '*' + this.$t('no subject') + '*') ? '*no subject*' : filter; }),
84-
add_confidential: this.confidentials,
93+
filters: {
94+
subjects: this.filters.subjects.map((filter) => { return (filter === '*' + this.$t('no subject') + '*') ? '*no subject*' : filter; }),
95+
show_archives: this.filters.show_archives,
96+
show_confidential: this.show_confidential,
97+
},
8598
items: this.filtered_notes,
8699
},
87100
app_version: require('../../package.json').version,
88101
date: new Date(),
89102
}, null, (this.readable) ? '\t': '');
90103
},
91-
filters() {
104+
availableFilters() {
92105
let result = ['*' + this.$t('no subject') + '*'];
93106
94107
result = result.concat(Object.keys(this.$store.state.subjects));

src/views/ImportData.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ div
1616
v-card-actions
1717
v-btn(large, block, color="primary", @click="load", :disabled="userData.trim() === ''", :loading="loading")
1818
v-icon unarchive
19-
span {{ $t('Import your data') }}
19+
span {{ $t('Import your data manually') }}
2020
</template>
2121

2222
<script>

0 commit comments

Comments
 (0)