Working v0
This commit is contained in:
+31
-15
@@ -11,9 +11,7 @@
|
||||
<script src="https://code.jquery.com/jquery-3.7.1.min.js"></script>
|
||||
<script src="https://cdn.jsdelivr.net/npm/vue@2.7.16/dist/vue.js"></script>
|
||||
<script src="https://cdn.jsdelivr.net/npm/sweetalert2@11"></script>
|
||||
<!-- <script src="https://cdnjs.cloudflare.com/ajax/libs/vue-resource/0.6.1/vue-resource.min.js"></script> -->
|
||||
<script src="https://cdn.jsdelivr.net/npm/vue-resource@1.5.3"></script>
|
||||
<script src="https://unpkg.com/htmx.org@2.0.2"></script>
|
||||
<script src="https://cdn.jsdelivr.net/npm/js-cookie@3.0.5/dist/js.cookie.min.js"></script>
|
||||
<script src="https://unpkg.com/vue-router@3/dist/vue-router.js"></script>
|
||||
|
||||
@@ -28,14 +26,22 @@
|
||||
|
||||
<link href="https://cdn.jsdelivr.net/npm/@mdi/font@7.4.47/css/materialdesignicons.min.css" rel="stylesheet">
|
||||
|
||||
<link href="https://fonts.cdnfonts.com/css/jetbrains-mono" rel="stylesheet">
|
||||
<style>
|
||||
.font {
|
||||
font-family: 'JetBrains Mono', sans-serif;
|
||||
}
|
||||
</style>
|
||||
|
||||
</head>
|
||||
<body hx-headers='{"X-CSRFToken": "{{ csrf_token }}"}'>
|
||||
<v-app>
|
||||
<body>
|
||||
<v-app class="font">
|
||||
<div id="main" data-app>
|
||||
|
||||
<nav class="navbar navbar-expand-lg bg-primary" data-bs-theme="dark">
|
||||
<div class="container-fluid">
|
||||
<a href="#" @click="lock_me" class="navbar-brand">{% trans "Lock" %}</a>
|
||||
|
||||
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarColor01" aria-controls="navbarColor01" aria-expanded="false" aria-label="Toggle navigation">
|
||||
<span class="navbar-toggler-icon"></span>
|
||||
</button>
|
||||
@@ -49,13 +55,13 @@
|
||||
</router-link>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<router-link class="nav-link" to="/item_list">{% trans "Items" %}</router-link>
|
||||
<router-link class="nav-link" to="/ItemView">{% trans "Items" %}</router-link>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<a class="nav-link" href="#">{% trans "Properties" %}</a>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<router-link class="nav-link" to="/encryption-testing">{% trans "Encryption" %}</router-link>
|
||||
<router-link class="nav-link" to="/EncryptionTesting">{% trans "Encryption" %}</router-link>
|
||||
</li>
|
||||
<li class="nav-item dropdown">
|
||||
<a class="nav-link dropdown-toggle" data-bs-toggle="dropdown" href="#" role="button" aria-haspopup="true" aria-expanded="false">{% trans "More" %}</a>
|
||||
@@ -77,7 +83,7 @@
|
||||
</nav>
|
||||
|
||||
<div id="app" class="container">
|
||||
<k356-loading :crypto_key="key" @update_key="update_key" v-if="locked"></k356-loading>
|
||||
<Loading :crypto_key="key" @update_key="update_key" v-if="locked"></Loading>
|
||||
<template v-if="!locked">
|
||||
<router-view :crypto_key="key"></router-view>
|
||||
</template>
|
||||
@@ -101,17 +107,17 @@
|
||||
|
||||
Vue.config.delimiters = ["[[", "]]"];
|
||||
|
||||
{% for name, value in components.items %}
|
||||
{% include value.path %}
|
||||
Vue.component("{{ name }}", {{ value.flat_name }});
|
||||
{% for name, path in components.items %}
|
||||
{% include path %}
|
||||
Vue.component("{{ name }}", {{ name }});
|
||||
{% endfor %}
|
||||
|
||||
const routes = [
|
||||
{ path: '/', component: null },
|
||||
{% for name, value in components.items %}
|
||||
{% for name, path in components.items %}
|
||||
{
|
||||
path: "/{{ name }}",
|
||||
component: {{ value.flat_name }},
|
||||
component: {{ name }},
|
||||
},
|
||||
{% endfor %}
|
||||
];
|
||||
@@ -131,7 +137,6 @@
|
||||
},
|
||||
methods: {
|
||||
update_key: function(key) {
|
||||
console.log(key);
|
||||
this.key.key = key;
|
||||
this.locked = key == null;
|
||||
},
|
||||
@@ -143,9 +148,9 @@
|
||||
}
|
||||
});
|
||||
|
||||
router.beforeEach((to, from) => {
|
||||
router.beforeEach((to, from, next) => {
|
||||
// Prevent from routing if key is not present.
|
||||
return approuter.key.key != null;
|
||||
next(approuter.key.key != null);
|
||||
});
|
||||
|
||||
</script>
|
||||
@@ -159,5 +164,16 @@
|
||||
refresh_csrftoken();
|
||||
</script>
|
||||
|
||||
<script type="module">
|
||||
import { useDate } from './vuetify.js'
|
||||
|
||||
const date = useDate()
|
||||
|
||||
const formatted = date.format('2010-04-13', 'fullDateWithWeekday')
|
||||
|
||||
console.log(formatted) // Tuesday, April 13, 2010
|
||||
</script>
|
||||
|
||||
|
||||
</body>
|
||||
</html>
|
||||
|
||||
@@ -0,0 +1,104 @@
|
||||
{% load i18n %}
|
||||
|
||||
{% block component %}
|
||||
<v-data-table
|
||||
:headers="items_headers"
|
||||
:items="items"
|
||||
:items-per-page="50"
|
||||
:search="search"
|
||||
:group-by="group_by"
|
||||
loading
|
||||
dense>
|
||||
<template v-slot:top>
|
||||
<v-toolbar flat>
|
||||
|
||||
<v-text-field v-model="search" append-icon="mdi-magnify" label="Search" single-line hide-details></v-text-field>
|
||||
<v-divider class="mx-4" insert vertical></v-divider>
|
||||
|
||||
<v-spacer></v-spacer>
|
||||
|
||||
<v-dialog v-model="dialog" max-width="500px">
|
||||
<template v-slot:activator="{ on, attrs }">
|
||||
<v-btn color="primary" dark class="mb-2" v-bind="attrs" v-on="on">
|
||||
<v-icon small class="mr-2">mdi-plus</v-icon>
|
||||
{% trans "New" %}
|
||||
</v-btn>
|
||||
</template>
|
||||
|
||||
<v-card>
|
||||
<v-card-title>
|
||||
<span class="text-h5"> [[ editedItem.id ]]</span>
|
||||
</v-card-title>
|
||||
<v-card-text>
|
||||
<v-container>
|
||||
<v-row>
|
||||
<template v-for="field in editable_fields">
|
||||
<template v-if="field.field_widget == 'v-select'">
|
||||
<v-select
|
||||
v-model="editedItem[field.value]"
|
||||
:items="items_relations[field.value]"
|
||||
:label="field.text"
|
||||
item-text="name"
|
||||
item-value="id"
|
||||
persistent-hint>
|
||||
<template slot="item" slot-scope="data">
|
||||
[[ data.item.name ]] - [[ data.item.custom_identifier ]]
|
||||
</template>
|
||||
</v-select>
|
||||
</template>
|
||||
<template v-else>
|
||||
<component :is="field.field_widget" v-model="editedItem[field.value]" :label="field.text"></component>
|
||||
</template>
|
||||
</template>
|
||||
</v-row>
|
||||
</v-container>
|
||||
</v-card-text>
|
||||
|
||||
<v-card-actions>
|
||||
<v-spacer></v-spacer>
|
||||
<v-btn color="blue darken-1" text @click="close">
|
||||
<v-icon small class="mr-2">mdi-cancel</v-icon>
|
||||
{% trans "Cancel" %}
|
||||
</v-btn>
|
||||
<v-btn color="blue darken-1" text @click="save">
|
||||
<v-icon small class="mr-2">mdi-content-save-edit</v-icon>
|
||||
{% trans "Save" %}
|
||||
</v-btn>
|
||||
</v-card-actions>
|
||||
</v-card>
|
||||
</v-dialog>
|
||||
|
||||
<v-dialog v-model="dialogDelete" max-width="500px">
|
||||
<v-card>
|
||||
<v-card-title class="text-h5">{% trans "Are you sure you want to delete this item?" %}</v-card-title>
|
||||
<v-card-actions>
|
||||
<v-spacer></v-spacer>
|
||||
<v-btn color="blue darken-1" text @click="closeDelete">
|
||||
<v-icon small class="mr-2">mdi-cancel</v-icon>
|
||||
{% trans "Cancel" %}
|
||||
</v-btn>
|
||||
<v-btn color="blue darken-1" text @click="deleteItemConfirm">
|
||||
<v-icon small class="mr-2">mdi-delete-forever</v-icon>
|
||||
{% trans "OK" %}
|
||||
</v-btn>
|
||||
<v-spacer></v-spacer>
|
||||
</v-card-actions>
|
||||
</v-card>
|
||||
</v-dialog>
|
||||
</v-toolbar>
|
||||
</template>
|
||||
|
||||
<template v-slot:item.id="{ item }">
|
||||
[[ item.id.slice(0, 8) ]]...
|
||||
</template>
|
||||
<template v-slot:item.actions="{ item }">
|
||||
<v-icon small class="mr-2" @click="editItem(item)">mdi-pencil</v-icon>
|
||||
<v-icon small @click="deleteItem(item)">mdi-delete</v-icon>
|
||||
</template>
|
||||
|
||||
<template v-slot:no-data>
|
||||
<v-btn color="primary" @click="initialize">{% trans "Reset" %}</v-btn>
|
||||
</template>
|
||||
|
||||
</v-data-table>
|
||||
{% endblock %}
|
||||
@@ -0,0 +1,87 @@
|
||||
{% block component %}
|
||||
{{ name }} = {
|
||||
template: "#{{ name }}",
|
||||
delimiters: ["[[", "]]"],
|
||||
props: ["crypto_key", "items", "items_headers", "items_relations", "group_by"],
|
||||
|
||||
data: function() {
|
||||
return {
|
||||
dialog: false,
|
||||
dialogDelete: false,
|
||||
editedIndex: -1,
|
||||
defaultItem: {},
|
||||
editedItem: {},
|
||||
search: null,
|
||||
}
|
||||
},
|
||||
|
||||
computed: {
|
||||
editable_fields: function() {
|
||||
return this.items_headers.filter(e => e.editable)
|
||||
},
|
||||
},
|
||||
|
||||
watch: {
|
||||
dialog (val) {
|
||||
val || this.close()
|
||||
},
|
||||
dialogDelete (val) {
|
||||
val || this.closeDelete()
|
||||
},
|
||||
},
|
||||
|
||||
methods: {
|
||||
|
||||
editItem (item) {
|
||||
this.editedIndex = this.items.indexOf(item)
|
||||
this.editedItem = Object.assign({}, item)
|
||||
this.dialog = true
|
||||
},
|
||||
|
||||
deleteItem (item) {
|
||||
this.editedIndex = this.items.indexOf(item)
|
||||
this.editedItem = Object.assign({}, item)
|
||||
this.dialogDelete = true
|
||||
},
|
||||
|
||||
deleteItemConfirm () {
|
||||
var self = this
|
||||
var item = this.items[this.editedIndex]
|
||||
|
||||
this.$emit("deleteItem", this.editedIndex)
|
||||
this.closeDelete()
|
||||
|
||||
},
|
||||
|
||||
close () {
|
||||
this.dialog = false
|
||||
this.editedItem = Object.assign({}, this.defaultItem)
|
||||
this.editedIndex = -1
|
||||
},
|
||||
|
||||
closeDelete () {
|
||||
this.dialogDelete = false
|
||||
this.editedItem = Object.assign({}, this.defaultItem)
|
||||
this.editedIndex = -1
|
||||
},
|
||||
|
||||
|
||||
save () {
|
||||
|
||||
if (this.editedIndex > -1) {
|
||||
|
||||
this.$emit("editItem", this.editedIndex, this.editedItem)
|
||||
|
||||
} else {
|
||||
|
||||
console.log('createItem emit', this.editedItem)
|
||||
this.$emit("createItem", this.editedItem)
|
||||
|
||||
}
|
||||
|
||||
this.close()
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
{% endblock %}
|
||||
Reference in New Issue
Block a user