Skip to content
This repository has been archived by the owner on Sep 13, 2023. It is now read-only.

Commit

Permalink
Generate file name if needed. (#51)
Browse files Browse the repository at this point in the history
  • Loading branch information
slabruyere authored and lauthieb committed Oct 29, 2018
1 parent e2caeb8 commit c83a682
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 42 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@ <h2 class="text-red" v-if="displayDupError">Oh sorry, you can't have duplicated
type="text"
ref="noteName"
v-model="note.name"
placeholder="Your note name"
required>
placeholder="Your note name">
</b-input>
</b-field>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,15 @@
import languages from '@/assets/data/languages.json';
import converter from '@/converter';
const noteNameCharacters = "abcdef0123456789";
const generateNoteName = () => {
let text = "";
for (let i = 0; i < 32; i += 1)
text += noteNameCharacters.charAt(Math.floor(Math.random() * 16));
return text;
};
export default {
name: 'cn-create-note-modal',
components: { editor },
Expand Down Expand Up @@ -44,21 +53,29 @@
createNote() {
if (!this.containsDupFiles()) {
let separator = '-';
let prefix = 'note';
if (this.gistsSelected) {
separator = '.';
prefix = 'gist';
}
this.files.forEach(file => {
let name;
this.files.forEach((file, i) => {
name = file.name || `${prefix}file${(i + 1)}`;
this.note.files[
`${file.name}${separator}${converter.languageToExtension(
`${name}${separator}${converter.languageToExtension(
file.language
)}`
] = file;
});
this.note.createdAt = new Date();
this.note.updatedAt = new Date();
if (!this.note.name || this.note.name.trim() === "") {
this.note.name = `${prefix}:${generateNoteName()}`;
}
this.addNote(this.note).then(() => {
this.$parent.close();
});
Expand Down Expand Up @@ -98,25 +115,8 @@
computed: {
...mapGetters(['gistsSelected']),
isDisabled() {
if (this.gistsSelected) {
return this.files.some(
file =>
!/^[^.]*$/.test(file.name) ||
!/\S/.test(file.name) ||
!/\S/.test(file.language) ||
!/\S/.test(file.content)
);
}
return (
!/\S/.test(this.note.name) ||
this.files.some(
file =>
!/^[^.]*$/.test(file.name) ||
!/\S/.test(file.name) ||
!/\S/.test(file.language) ||
!/\S/.test(file.content)
)
return this.files.some(
file => !/\S/.test(file.content)
);
},
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,25 +137,8 @@
computed: {
...mapGetters(['gistsSelected']),
isDisabled() {
if (this.gistsSelected) {
return this.files.some(
file =>
!/^[^.]*$/.test(file.name) ||
!/\S/.test(file.name) ||
!/\S/.test(file.language) ||
!/\S/.test(file.content)
);
}
return (
!/\S/.test(this.note.name) ||
this.files.some(
file =>
!/^[^.]*$/.test(file.name) ||
!/\S/.test(file.name) ||
!/\S/.test(file.language) ||
!/\S/.test(file.content)
)
return this.files.some(
file => !/\S/.test(file.content)
);
},
},
Expand Down

0 comments on commit c83a682

Please sign in to comment.