Skip to content

Commit

Permalink
Frontend for adding Book Selections
Browse files Browse the repository at this point in the history
  • Loading branch information
audiodude committed Jul 16, 2023
1 parent aa795f0 commit d42d24a
Show file tree
Hide file tree
Showing 4 changed files with 103 additions and 1 deletion.
77 changes: 77 additions & 0 deletions wp1-frontend/src/components/BookBuilder.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
<template>
<BaseBuilder
:key="$route.path"
:listName="'Book Selection'"
:model="'wp1.selection.models.book'"
:params="params"
:builderId="$route.params.builder_id"
:invalidItems="invalidItems"
@onBuilderLoaded="onBuilderLoaded"
@onBeforeSubmit="onBeforeSubmit"
@onValidationError="onValidationError"
>
<template #create-desc>
<p>
Use this tool to create an article selection list for the Wikipedia
project of your choice, based off a Wikipedia Book that you already
created. You must first "save" your book, then enter the URL of the
saved book. Your selection will be saved in public cloud storage and can
be accessed through URLs that will be provided once it has been saved.
</p>
<p class="mb-0">
For more information on creating a Book selection, see the
<a href="https://wp1.readthedocs.io/en/latest/user/selections/"
>end user documentation</a
>
</p>
</template>
<template #extra-params>
<div id="items" class="form-group m-4">
<label for="items">URL</label>
<input
id="bookUrl"
ref="bookUrl"
class="form-control my-2"
v-model="params.url"
/>
<div class="invalid-feedback">Please provide a valid URL</div>
</div>
</template>
</BaseBuilder>
</template>

<script>
import BaseBuilder from './BaseBuilder.vue';
export default {
components: { BaseBuilder },
name: 'BookBuilder',
data: function () {
return {
url: '',
invalidItems: '',
params: {},
};
},
methods: {
validationOnBlur: function (event) {
if (event.target.value) {
event.target.classList.remove('is-invalid');
} else {
event.target.classList.add('is-invalid');
}
},
onBuilderLoaded: function (builder) {
this.params = builder.params;
},
onBeforeSubmit: function () {
this.$refs.bookUrl.setCustomValidity('');
},
onValidationError: function (data) {
this.$refs.bookUrl.setCustomValidity('URL not valid');
},
},
};
</script>

<style scoped></style>
2 changes: 1 addition & 1 deletion wp1-frontend/src/components/PetscanBuilder.vue
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ import BaseBuilder from './BaseBuilder.vue';
export default {
components: { BaseBuilder },
name: 'SimpleBuilder',
name: 'PetscanBuilder',
data: function () {
return {
url: '',
Expand Down
10 changes: 10 additions & 0 deletions wp1-frontend/src/components/SecondaryNav.vue
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,16 @@
>Petscan Selection</router-link
>
</li>
<li
:class="
'nav-item ' +
(this.$route.path.startsWith('/selections/book') ? 'active' : '')
"
>
<router-link class="nav-link" to="/selections/book"
>Book Selection</router-link
>
</li>
</ul>
</div>
</nav>
Expand Down
15 changes: 15 additions & 0 deletions wp1-frontend/src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import VueRouter from 'vue-router';

import App from './App.vue';
import ArticlePage from './components/ArticlePage.vue';
import BookBuilder from './components/BookBuilder.vue';
import PetscanBuilder from './components/PetscanBuilder.vue';
import SimpleBuilder from './components/SimpleBuilder.vue';
import SparqlBuilder from './components/SparqlBuilder.vue';
Expand Down Expand Up @@ -118,6 +119,13 @@ const routes = [
title: () => BASE_TITLE + ' - Create Petscan Selection',
},
},
{
path: '/selections/book',
component: BookBuilder,
meta: {
title: () => BASE_TITLE + ' - Create Book Selection',
},
},
{
path: '/selections/simple/:builder_id',
component: SimpleBuilder,
Expand All @@ -139,6 +147,13 @@ const routes = [
title: () => BASE_TITLE + ' - Edit Petscan Selection',
},
},
{
path: '/selections/book/:builder_id',
component: PetscanBuilder,
meta: {
title: () => BASE_TITLE + ' - Edit Book Selection',
},
},
{
path: '/selections/:builder_id/zim',
component: ZimFile,
Expand Down

0 comments on commit d42d24a

Please sign in to comment.