Ajout de l'E2E #10

Merged
Shikiryu merged 3 commits from e2e into master 2020-03-16 17:06:09 +01:00
5 changed files with 98 additions and 50 deletions
Showing only changes of commit 407b7c2774 - Show all commits

View File

@ -24,7 +24,9 @@
"vue-template-compiler": "^2.6.10"
},
"dependencies": {
"endcrypt": "^1.2.3",
"tabler-ui": "^0.0.34",
"textarea-caret": "^3.1.0"
"textarea-caret": "^3.1.0",
"vue2-storage": "^4.0.5"
}
}

76
resources/js/app.js vendored
View File

@ -27,11 +27,67 @@ window.Vue = require('vue');
* or customize the JavaScript scaffolding to fit your unique needs.
*/
import App from './components/App.vue';
import Vue from 'vue';
import Autocomplete from './components/Autocomplete.vue';
import { Endcrypt } from 'endcrypt';
import { Vue2Storage } from 'vue2-storage'
const e = new Endcrypt();
// You can specify the plug-in configuration when connecting, passing the second object to Vue.use
Vue.use(Vue2Storage, {
prefix: 'journal_',
driver: 'session',
ttl: 60 * 60 * 24 * 1000
});
Vue.config.productionTip = false;
/** Function for collapse card */
document.querySelectorAll('[data-toggle="card-collapse"]').forEach(function(card){
let storeId = 'store';
let storeElement = document.getElementById(storeId);
Vue.component(
'messageform', {
name: 'MessageForm',
props: {
'mustencrypt': {
type: Boolean,
default: true
},
'possible': {
type: Boolean,
default: false
}
},
methods: {
encrypt: function(evt) {
evt.preventDefault();
if (this.mustencrypt) {
// https://www.npmjs.com/package/endcrypt
let plain = document.querySelector("[name=message]").value;
let encryptedMessage = JSON.stringify(e.encryptWithKey(plain, this.$storage.get('passphrase')));
document.querySelector("[name=message]").value = encryptedMessage;
}
document.getElementById('messageForm').submit();
return false;
}
},
beforeMount: function() {
let passphrase = this.$storage.get('passphrase', '');
if (passphrase === '') {
passphrase = prompt('Merci d\'entrer votre phrase de passe');
this.$storage.set('passphrase', passphrase);
}
/** Function for collapse and decrypt cards */
let $this = this;
document.querySelectorAll('[data-toggle="card-collapse"]').forEach(function(card){
let cardBody = card.parentElement.parentElement.parentElement.querySelector("[data-encrypt]");
try {
let cardBodyDecrypted = JSON.parse(cardBody.innerHTML.trim());
cardBody.innerHTML = e.decryptWithKey(cardBodyDecrypted, $this.$storage.get('passphrase'));
} catch (e) {
console.log('can\'t decode '+ cardBody.innerHTML);
console.log(e);
}
card.addEventListener('click', function(evt) {
let $card = this.parentElement.parentElement.parentElement;
@ -39,8 +95,14 @@ document.querySelectorAll('[data-toggle="card-collapse"]').forEach(function(card
evt.preventDefault();
return false;
});
});
});
},
components: {
Autocomplete
}
}
);
const app = new Vue({
render: h => h(App),
}).$mount('#app');
new Vue({
el: '#store'
});

View File

@ -1,15 +0,0 @@
<template>
<div>
<Autocomplete hasLabel="false" id="message" name="message" rows="5" placeholder="Que s'est-il passé aujourd'hui ?" textarea="true" />
</div>
</template>
<script>
import Autocomplete from './Autocomplete.vue';
export default {
components: {
Autocomplete
}
}
</script>
<style scoped></style>

View File

@ -28,7 +28,7 @@
props: ["items", "placeholder", "label", "textarea", "rows", "cols", "hasLabel", "name"],
data() {
return {
id: 'input-' + parseInt(Math.random() * 1000, 10),
id: 'input-' + (Math.random() * 1000 | 0),
inputValue: "",
searchMatch: [],
selectedIndex: 0,
@ -70,7 +70,6 @@
watch: {
inputValue() {
this.focus();
console.log(this.inputSplitted)
this.selectedIndex = 0;
this.wordIndex = this.inputSplitted.length - 1;
}

View File

@ -70,6 +70,15 @@
<div class="col-md-12">
@if($already)
<div class="alert alert-primary">L'activité du jour a déjà été entrée.</div>
<div id="store">
@component('components/app', [
'route' => url('store'),
'crsf' => csrf_field(),
'mustencrypt' => $must_encrypt,
'possible' => false,
])
@endcomponent
</div>
@else
<div class="row">
<div class="col-sm-12">
@ -78,24 +87,15 @@
<h3 class="card-title">{{ strftime('%B %G', $today->format('U')) }}</h3>
</div>
<div class="card-body">
<form action="{{ url('store') }}" method="post" accept-charset="utf-8">
@csrf
<div class="contact-form">
<div class="form-group">
<label class="control-label col-sm-5" for="message">Quoi de neuf aujourd'hui ?</label>
<div class="col-sm-10">
<div id="app">
<div id="store">
@component('components/app', [
'route' => url('store'),
'crsf' => csrf_field(),
'mustencrypt' => $must_encrypt,
'possible' => !$already,
])
@endcomponent
</div>
<span class="text-danger">{{ $errors->first('message') }}</span>
</div>
</div>
<div class="form-group">
<div class="col-sm-offset-2 col-sm-10">
<button type="submit" class="btn btn-primary ml-auto">J'enregistre ma journée</button>
</div>
</div>
</div>
</form>
</div>
</div>
</div>
@ -113,7 +113,7 @@
<a href="#" class="card-options-remove" data-toggle="card-remove"><i class="fe fe-x"></i></a>
</div>
</div>
<div class="card-body">
<div class="card-body" data-encrypt>
{!! $tag_detector->linkTagFrom($post->content) !!}
</div>
<div class="card-footer">