Added edit button for title

This commit is contained in:
CakesTwix 2024-09-26 14:24:26 +03:00
parent a396859616
commit ced9904772
Signed by: CakesTwix
GPG key ID: 7B11051D5CE19825
6 changed files with 130 additions and 10 deletions

View file

@ -100,3 +100,22 @@ def update_route(codename):
except Exception as e: except Exception as e:
message = f"Error: {str(e)}" message = f"Error: {str(e)}"
return {"error": message} return {"error": message}
@api_bp.route("/api/edit", methods=["POST"])
def edit_route():
config = initiate_config()
titles = config.titles_config
for title in titles.sections():
if titles._sections[title]["hash"] != request.json["hash"]:
continue
titles._sections[title]["episode_index"] = request.json["episodeIndex"]
titles._sections[title]["season_number"] = request.json["seasonNumber"]
titles._sections[title]["torrent_name"] = request.json["torrentName"]
titles._sections[title]["download_dir"] = request.json["downloadDir"]
titles._sections[title]["publish_date"] = request.json["publishDate"]
titles._sections[title]["adjusted_episode_number"] = request.json["adjustedEpisodeNumber"]
with open("data/titles.ini", "w") as f:
titles.write(f)
return jsonify({"result": True})

View file

@ -1,7 +1,7 @@
{ {
"name": "frontend", "name": "frontend",
"private": true, "private": true,
"version": "1.0.4", "version": "1.0.5",
"type": "module", "type": "module",
"scripts": { "scripts": {
"dev": "vite", "dev": "vite",

View file

@ -48,6 +48,9 @@ export default {
}, },
deleteTitle() { deleteTitle() {
this.$emit('delete-title', this.title.codename); this.$emit('delete-title', this.title.codename);
},
editTitle() {
this.$emit('edit-title', this.title.codename);
} }
} }
} }

View file

@ -8,9 +8,9 @@
<p class="secondary-text">Зручний сайт для завантаження аніме до медіасерверу Jellyfin</p> <p class="secondary-text">Зручний сайт для завантаження аніме до медіасерверу Jellyfin</p>
<div class="space"></div> <div class="space"></div>
<nav class="center-align"> <nav class="center-align">
<a href="https://github.com"><i class="chip circle">code</i></a> <a href="https://codeberg.org/CakesTwix/Toloka2WebV2"><i class="chip circle">code</i></a>
<a href="https://github.com"><i class="chip circle">bug_report</i></a> <a href="https://codeberg.org/CakesTwix/Toloka2WebV2/issues"><i class="chip circle">bug_report</i></a>
<a href="https://mastodon.com"><i class="chip circle">diversity_3</i></a> <a href="https://shkey.cakestwix.com/@CakesTwix"><i class="chip circle">diversity_3</i></a>
</nav> </nav>
</div> </div>
</article> </article>

View file

@ -29,8 +29,9 @@
</button> </button>
</nav> </nav>
<TitleCard v-for="title in titles" :key="title.codename" :title="title" @update-title="updateByCodename" @delete-title="deleteByCodename" /> <TitleCard v-for="title in titles" :key="title.codename" :title="title" @update-title="updateByCodename"
@delete-title="deleteByCodename" @edit-title="openEditDialog" />
</main> </main>
<main class="responsive middle-align center-align" v-if="isEmpty"> <main class="responsive middle-align center-align" v-if="isEmpty">
<div class="padding absolute center middle"> <div class="padding absolute center middle">
@ -61,6 +62,70 @@
</nav> </nav>
</dialog> </dialog>
<dialog class="active" v-if="Object.keys(editFormData).length > 0">
<h5 class="primary-text">Редагування</h5>
<form @submit.prevent="editTitle" class="grid">
<div class="field label prefix border s12">
<i>folder</i>
<input type="text" v-model="editFormData.download_dir" />
<label>Назва директорії</label>
</div>
<div class="field label prefix border s12">
<i>folder</i>
<input type="text" v-model="editFormData.torrent_name" />
<label>Назва торренту</label>
</div>
<div class="field label prefix border s12 l4">
<i>folder</i>
<input type="text" v-model="editFormData.episode_index" />
<label>Епізод</label>
</div>
<div class="field label prefix border s12 l4">
<i>folder</i>
<input type="text" v-model="editFormData.season_number" />
<label>Сезон</label>
</div>
<div class="field label prefix border s12 l4">
<i>folder</i>
<input type="text" v-model="editFormData.publish_date" />
<label>Дата релізу</label>
</div>
<div class="field label prefix border s12 l4">
<i>folder</i>
<input type="text" v-model="editFormData.adjusted_episode_number" />
<label>Скільки додати до епізоду</label>
</div>
<div class="field label prefix border s12 l4">
<i>folder</i>
<input type="text" v-model="editFormData.release_group" readonly />
<label>Автор релізу</label>
<span class="helper">Тільки для читання</span>
</div>
<div class="field label prefix border s12 l4">
<i>folder</i>
<input type="text" v-model="editFormData.hash" readonly />
<label>Хеш</label>
<span class="helper">Тільки для читання</span>
</div>
<div class="field label prefix border s12 l4">
<i>folder</i>
<input type="text" v-model="editFormData.guid" readonly />
<label>GUID</label>
<span class="helper">Тільки для читання</span>
</div>
<nav class="right-align small-padding s12">
<button class="border small-round" @click="closeDialog">
<i>cancel</i>
<span>Закрити</span>
</button>
<button class="border small-round" type="submit">
<i>edit</i>
<span>Оновити</span>
</button>
</nav>
</form>
</dialog>
</template> </template>
<script> <script>
@ -78,11 +143,12 @@ export default {
search: '', // Search bar search: '', // Search bar
update: {}, // Update stuff, notif update: {}, // Update stuff, notif
isUpdated: false, // Update notif isUpdated: false, // Update notif
isEmpty: false, isEmpty: false, // For first start app without any titles
editFormData: {} // Data for edit dialog
}; };
}, },
created() { created() {
this.fetchTorrents() this.fetchTorrents() // Load titles.ini
}, },
methods: { methods: {
@ -90,7 +156,7 @@ export default {
void await axios.get(`/api/titles`).then(response => { void await axios.get(`/api/titles`).then(response => {
this.titles = response.data this.titles = response.data
if (this.titles.length == 0){ if (this.titles.length == 0) {
this.isEmpty = true this.isEmpty = true
} }
}) })
@ -133,6 +199,38 @@ export default {
this.titles.sort((a, b) => a.release_group.localeCompare(b.release_group)); this.titles.sort((a, b) => a.release_group.localeCompare(b.release_group));
} }
ui('#sort-menu'); ui('#sort-menu');
},
async openEditDialog(codename) {
const title = this.titles.find(title => title.codename === codename);
if (title) {
this.editFormData = title;
} else {
console.log('Error open edit dialog');
}
},
async editTitle() {
const formData = {
downloadDir: this.editFormData.download_dir,
torrentName: this.editFormData.torrent_name,
episodeIndex: this.editFormData.episode_index,
seasonNumber: this.editFormData.season_number,
publishDate: this.editFormData.publish_date,
releaseGroup: this.editFormData.release_group,
hash: this.editFormData.hash,
guid: this.editFormData.guid,
adjustedEpisodeNumber: this.editFormData.adjusted_episode_number
};
try {
const response = await axios.post('/api/edit', formData);
} catch (error) {
console.error("Error:", error);
} finally {
this.closeDialog();
}
},
closeDialog() {
this.editFormData = {};
} }
} }
} }

View file

@ -20,7 +20,7 @@
<article class="secondary-text"> <article class="secondary-text">
<a class="row wave"><i>title</i> Toloka2Web v2 Vue Version</a> <a class="row wave"><i>title</i> Toloka2Web v2 Vue Version</a>
<hr> <hr>
<a class="row wave"><i>conversion_path</i> v1.0.4</a> <a class="row wave"><i>conversion_path</i> v1.0.5</a>
</article> </article>
</template> </template>