Browse Source

Refactor from Django json_script to /me API

pull/148/head
Clemens Wolff 5 years ago
parent
commit
7f83f716fb
3 changed files with 10 additions and 23 deletions
  1. 9
      app/server/static/js/projects.js
  2. 22
      app/server/static/js/projects.vue
  3. 2
      app/server/templates/projects.html

9
app/server/static/js/projects.js

@ -6,12 +6,5 @@ new Vue({
components: { Projects },
data: {
djangoContext: {
username: JSON.parse(document.getElementById('django.username').textContent),
isSuperuser: JSON.parse(document.getElementById('django.is_superuser').textContent),
},
},
template: '<Projects v-bind="djangoContext" />',
template: '<Projects />',
});

22
app/server/static/js/projects.vue

@ -204,17 +204,6 @@ const baseUrl = window.location.href.split('/').slice(0, 3).join('/');
export default {
filters: { title, daysAgo },
props: {
username: {
type: String,
required: true,
},
isSuperuser: {
type: Boolean,
default: false,
},
},
data: () => ({
items: [],
isActive: false,
@ -227,6 +216,8 @@ export default {
descriptionError: '',
projectTypeError: '',
projectNameError: '',
username: '',
isSuperuser: false,
}),
computed: {
@ -236,8 +227,13 @@ export default {
},
created() {
axios.get(`${baseUrl}/v1/projects`).then((response) => {
this.items = response.data;
Promise.all([
axios.get(`${baseUrl}/v1/projects`),
axios.get(`${baseUrl}/v1/me`),
]).then(([projects, me]) => {
this.items = projects.data;
this.username = me.data.username;
this.isSuperuser = me.data.is_superuser;
});
},

2
app/server/templates/projects.html

@ -6,7 +6,5 @@
<div id="projects_root"></div>
{% endblock %}
{% block footer %}
{{ user.get_username | json_script:"django.username" }}
{{ user.is_superuser | json_script:"django.is_superuser" }}
{% render_bundle 'projects' 'js' %}
{% endblock %}
Loading…
Cancel
Save