Commit d4ce8e44 authored by David Foucher's avatar David Foucher

Add possibility to modify last modification

Hide modification button on rule view if a modifiction exists already
parent ee4792ba
Pipeline #2584 canceled with stage
......@@ -40,7 +40,7 @@
<div v-if="modificationInProgress" class="mt-5">
<h2>Modification en cours...</h2>
</div>
<img src="./../assets/images/loading.gif" alt="loading...">
<img src="./../assets/images/loading.gif" alt="loading...">
</div>
</div>
</div>
......@@ -61,6 +61,7 @@
rules: [],
isLoading: true,
windowLocationHash: decodeURI(window.location.hash),
modificationInProgress: false,
rerenderKey: 0,
collapsed: false,
currentRuleName: decodeURI(window.location.hash).split('#').pop() == "modified" ? decodeURI(window.location.hash).split('#')[1]:decodeURI(window.location.hash).split('#').pop(),
......
......@@ -16,7 +16,7 @@
</div>
<div class="col-md-6 col-sm-12 col-xs-12">
<h4 v-if="isEditMode" class="pull-right"><em>Modification de la règle</em></h4>
<input v-else v-b-modal.auth-modal type="button" class="main-button-primary btn pull-right" value="Soumettre une modification"/>
<input v-else-if="this.modifiedHashFlag | this.newModification" v-b-modal.auth-modal type="button" class="main-button-primary btn pull-right" value="Soumettre une modification"/>
<!-- TODO: show gitlab link of modification if exists -->
</div>
</div>
......@@ -46,7 +46,7 @@
<button v-b-modal.mail-modal class="btn main-button-primary pull-right">Enregistrer</button>
</div>
</div>
<div class="row mb-3">
<div v-if="content" class="row mb-3">
<label for="content"><u>Contenu de la règle</u></label>
<textarea-autosize id="content" v-model="content" class="rule-modification-text" :class="{editErrorClass: error_flags.notModified }"></textarea-autosize>
<span v-if="error_flags.notModified" class="text-danger font-weight-light">Aucune modification n'a été renseignée</span>
......@@ -114,9 +114,11 @@
modifiedHashFlag: decodeURI(window.location.hash).split('#').pop() == "modified",
isLoading: true,
ruleData: this.data,
modification_list: [],
modification_list: {},
commit_id: '',
content: '',
comment: '',
filename: 'trefle/config/rules/' + this.path,
isEditMode: '',
viewModification: false,
auth: {
......@@ -138,7 +140,7 @@
this.updateLayout();
window.addEventListener('popstate', () => {
this.updateLayout();
this.updateLayout();
})
},
computed: {
......@@ -154,6 +156,9 @@
ruleToEdit: function() {
return this.ruleData;
},
newModification: function() {
return Boolean(!this.modification_count)
}
},
methods: {
updateLayout: function() {
......@@ -172,6 +177,9 @@
.get('/source/modified?branch='+encodeURIComponent(this.displayedName))
.then(response => {
this.modification_list = response.body;
if(Object.keys(this.modification_list).length) {
this.commit_id = this.modification_list[Object.keys(this.modification_list)[0]].id;
}
this.isLoading = false;
return true;
}, response => {
......@@ -179,6 +187,25 @@
return false;
})
},
getContentRule: function(){
if(this.commit_id) {
let data_param = {
'file': this.filename,
'commit_id': this.commit_id,
}
this.$http
.get('/source/file', {params: data_param})
.then(response => {
this.content = response.body;
return true;
}, response => {
if(response.status == 500) this.content = '';
return false;
})
} else {
this.content = this.ruleData
}
},
auth_to_edit: function () {
this.error_flags.noUser = false;
this.error_flags.noPass = false;
......@@ -195,7 +222,7 @@
.then(() => {
this.viewModification = false;
this.$parent.collapsed = true;
this.content = this.ruleToEdit;
this.getContentRule();
this.isEditMode=!this.isEditMode;
this.$bvModal.hide("auth-modal");
}, error => {
......@@ -237,14 +264,17 @@
this.error_flags.noResume = true;
return false;
}
const postData = {
let commitId = (this.commit_id != '') ? {"commit_id" : this.commit_id} : {}
const prePostData = {
author_email:this.auth.email,
author_name:this.auth.email.split("@")[0],
title: this.displayedName,
comment: this.comment,
content: this.content,
filename: 'trefle/config/rules/' + this.path
filename: this.filename
}
let postData = {...prePostData, ...commitId}
this.$http
.post('/source/save', postData)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment