Skip to content

Commit

Permalink
➕ merge pull request #130 from devmount/improve-translation-assignment
Browse files Browse the repository at this point in the history
Improve translation assignment
  • Loading branch information
devmount authored May 22, 2022
2 parents a9248d6 + 1b62f72 commit 0141f84
Show file tree
Hide file tree
Showing 4 changed files with 81 additions and 45 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ This is how the SongDrive Dashboard currently looks like.
- UI supports multiple languages (currently: EN, DE)
- Export and Import of complete SongDrive data

## Installation
## Installation for developers

1. Get all files
1. Get all files from repository

```bash
git clone https://github.com/devmount/SongDrive
Expand Down
20 changes: 20 additions & 0 deletions src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,26 @@ Vue.mixin({
pass += String.fromCharCode(rdm62 + (rdm62 < 10 ? 48 : rdm62 < 36 ? 55 : 61))
}
return pass;
},
// make a given string url friendly
urlify: (s) => {
return s.trim().toLowerCase()
.replace(/\s/g, '-')
.replace(/\//g, '-')
.replace(/\_/g, '-')
.replace(/'/g, '')
.replace(/"/g, '')
.replace(/,/g, '')
.replace(/;/g, '')
.replace(/\./g, '')
.replace(/:/g, '')
.replace(/#/g, '')
.replace(/ä/g, 'ae')
.replace(/ö/g, 'oe')
.replace(/ü/g, 'ue')
.replace(/ß/g, 'ss')
.replace(/²/g, '2')
.replace(/³/g, '3');
}
}
})
Expand Down
19 changes: 1 addition & 18 deletions src/modals/SetlistSet.vue
Original file line number Diff line number Diff line change
Expand Up @@ -372,24 +372,7 @@ export default {
},
// create a human readable record key of format YYYYMMDD-the-setlist-title
createSlug () {
return this.setlist.date.replace(/-/g, '') + '-' + this.slug(this.setlist.title);
},
slug (s) {
return s
.trim()
.toLowerCase()
.replace(/\s/g, '-')
.replace(/\//g, '-')
.replace(/'/g, '')
.replace(/"/g, '')
.replace(/,/g, '')
.replace(/;/g, '')
.replace(/\./g, '')
.replace(/:/g, '')
.replace(/ä/g, 'ae')
.replace(/ö/g, 'oe')
.replace(/ü/g, 'ue')
.replace(/ß/g, 'ss');
return this.setlist.date.replace(/-/g, '') + '-' + this.urlify(this.setlist.title);
},
cancel () {
this.$emit('closed');
Expand Down
83 changes: 58 additions & 25 deletions src/modals/SongSet.vue
Original file line number Diff line number Diff line change
Expand Up @@ -443,6 +443,17 @@ export default {
// new song should be created
if (!this.existing) {
this.$db.collection('songs').doc(slug).set(processedSong).then(() => {
// persist translation references
if (processedSong.translations.length > 0) {
processedSong.translations.forEach(t => {
if (t in this.songs) {
let tsong = this.songs[t];
if (!tsong.translations.includes(slug)) {
this.$db.collection('songs').doc(t).update({ translations: tsong.translations.concat([slug]) });
}
}
});
}
this.$emit('closed');
this.$emit('reset');
processedSong = {};
Expand All @@ -457,10 +468,28 @@ export default {
}
// existing song should be updated
else {
let initialSong = this.initialSong; // remember initial song data before update
// check if key remained (no title or language changes)
if (this.id == slug) {
// just update the existing setlist
this.$db.collection('songs').doc(this.id).update(processedSong).then(() => {
// just update the existing song
this.$db.collection('songs').doc(slug).update(processedSong).then(() => {
// persist translation references by removing and adding them
let translationDiff = initialSong.translations.filter(t => !processedSong.translations.includes(t));
if (translationDiff.length > 0) {
translationDiff.forEach(s => {
this.$db.collection('songs').doc(s).update({ translations: this.songs[s].translations.filter(t => t != slug) });
});
}
if (processedSong.translations.length > 0) {
processedSong.translations.forEach(t => {
if (t in this.songs) {
let tsong = this.songs[t];
if (!tsong.translations.includes(slug)) {
this.$db.collection('songs').doc(t).update({ translations: tsong.translations.concat([slug]) });
}
}
});
}
this.$emit('closed');
this.$emit('reset');
processedSong = {};
Expand All @@ -475,9 +504,6 @@ export default {
// update key by adding a new song, removing the old one and update references in other fields
this.$db.collection('songs').doc(slug).set(processedSong).then(() => {
this.$db.collection('songs').doc(this.id).delete();
this.$emit('closed');
this.$emit('reset');
processedSong = {};
// check existing setlists for this song id and update to new slug
for (const setlistId in this.setlists) {
const setlist = this.setlists[setlistId];
Expand All @@ -504,6 +530,26 @@ export default {
this.$db.collection('songs').doc(songId).update({ translations: updatedTranslationsList });
}
}
// persist translation references by removing and adding them
let translationDiff = initialSong.translations.filter(t => !processedSong.translations.includes(t));
if (translationDiff.length > 0) {
translationDiff.forEach(s => {
this.$db.collection('songs').doc(s).update({ translations: this.songs[s].translations.filter(t => t != slug) });
});
}
if (processedSong.translations.length > 0) {
processedSong.translations.forEach(t => {
if (t in this.songs) {
let tsong = this.songs[t];
if (!tsong.translations.includes(slug)) {
this.$db.collection('songs').doc(t).update({ translations: tsong.translations.concat([slug]) });
}
}
});
}
this.$emit('closed');
this.$emit('reset');
processedSong = {};
this.$router.push({ name: 'song-show', params: { id: slug }});
// toast success update message
this.$notify({
Expand All @@ -518,25 +564,8 @@ export default {
},
// create a human readable record key of format YYYYMMDD-the-setlist-title
createSlug () {
return this.slug(this.song.title) + '-' + this.song.language;
return this.urlify(this.song.title) + '-' + this.song.language;
},
slug (s) {
return s
.trim()
.toLowerCase()
.replace(/\s/g, '-')
.replace(/\//g, '-')
.replace(/'/g, '')
.replace(/"/g, '')
.replace(/,/g, '')
.replace(/;/g, '')
.replace(/\./g, '')
.replace(/:/g, '')
.replace(/ä/g, 'ae')
.replace(/ö/g, 'oe')
.replace(/ü/g, 'ue')
.replace(/ß/g, 'ss');
}
},
computed: {
// filter song list by search query
Expand Down Expand Up @@ -565,9 +594,11 @@ export default {
if (this.search.translations != '') {
for (const key in this.songs) {
if (this.songs.hasOwnProperty(key)) {
// exclude self assignment
if (this.existing && this.id == key) continue;
// search in title and subtitle
const song = this.songs[key];
let search = this.search.translations.toLowerCase();
// search in title and subtitle
if (
song.title.toLowerCase().indexOf(search) !== -1 ||
song.subtitle.toLowerCase().indexOf(search) !== -1 ||
Expand All @@ -579,7 +610,9 @@ export default {
}
return songs;
} else {
return this.songs;
let songs = JSON.parse(JSON.stringify(this.songs));
if (this.existing) delete songs[this.id];
return songs;
}
},
// calculate wether form errors occured
Expand Down

0 comments on commit 0141f84

Please sign in to comment.