command repository added and a lot of other changes

This commit is contained in:
Tobias Kurze
2019-08-13 15:30:57 +02:00
parent 6f0a2af15d
commit 55e2e9f6b9
9 changed files with 4423 additions and 4002 deletions

View File

@@ -12,157 +12,77 @@
<b-tabs v-model="tabIndex" card>
<b-tab title="Command list" active>
<template slot="title">
<font-awesome-icon icon="list"/>&nbsp;<font-awesome-icon icon="door-open"/>
<font-awesome-icon icon="list"/>&nbsp;<font-awesome-icon icon="cogs"/>
<strong>command</strong>&nbsp;<i>list</i>
</template>
<p>{{ $t('There are')}}&nbsp;{{commands.length}}&nbsp;{{ $t('commands defined')}}:</p>
<p>{{ $t('There are')}}&nbsp;{{commands.length}}&nbsp;{{ $t('recorder commands defined')}}:</p>
<b-card-group deck>
<b-card class="mb-2" style="max-width: 30rem; min-width:20rem;" v-for="(command) in commands"
:header="command.name + ' (' +command.number+ ')'" v-bind:key="command.id">
:header="command.name + ' (' +command.recorder_model.name+ ')'" v-bind:key="command.id">
<b-card-text>
<h5 class="card-title">{{ $t('name') }}:&nbsp;
<span v-if="!formEditField[command.id+'_name']">{{command.name}}&nbsp;
<span>{{command.name}}&nbsp;</span>
</h5>
<p class="card-text">
<small><strong>{{ $t('alternative_name') }}:</strong>&nbsp;
<span v-if="!formEditField[command.id+'_alternative_name']">{{command.alternative_name}}&nbsp;
<a class="float-right badge badge-pill badge-primary">
<font-awesome-icon
@click="initcommandUpdate(command, 'name')"
@click="initRecCommandUpdate(command, 'alternative_name')"
icon="pencil-alt"/>
</a>
</span>
<b-input-group v-else>
<b-form-input :id="command.id+'_name'" name="name"
v-model="updateValues[command.id+'_name']"
v-validate="'required|min:3'"
v-bind:class="{'is-danger': errors.has('name'), 'is-invalid': errors.has('name')}"
class="form-control" type="text"
:placeholder="'Name ('+command.name +')'"
required></b-form-input>
<b-input-group-append>
<b-button :disabled="errors.has('name')"
@click="updatecommand(command.id, 'name')"
variant="outline-success">
<font-awesome-icon icon="check"></font-awesome-icon>
</b-button>
</b-input-group-append>
</b-input-group>
</h5>
<p class="card-text"><strong>{{ $t('alternate_name') }}:</strong>&nbsp;
<span v-if="!formEditField[command.id+'_alternate_name']">{{command.alternate_name}}&nbsp;
<a class="float-right badge badge-pill badge-info">
<font-awesome-icon
@click="initcommandUpdate(command, 'alternate_name')"
icon="pencil-alt"/>
</a>
</span>
<b-input-group v-else size="sm">
<b-form-input name="alternate_name"
v-model="updateValues[command.id+'_alternate_name']"
class="form-control" type="text"
:placeholder="'Alternate name ('+command.alternate_name +')'"
@blur="updatecommand(command.id, 'alternate_name')"
@keyup.enter="updatecommand(command.id, 'alternate_name')"></b-form-input>
<b-input-group-append>
<b-button :disabled="errors.has('alternate_name')"
@click="updatecommand(command.id, 'alternate_name')"
variant="outline-success">
<font-awesome-icon icon="check"></font-awesome-icon>
</b-button>
</b-input-group-append>
</b-input-group>
</p>
<p class="card-text"><strong>{{ $t('command_number') }}:</strong>&nbsp;
<span v-if="!formEditField[command.id+'_number']">{{command.number}}&nbsp;
<a class="float-right badge badge-pill badge-info">
<font-awesome-icon
@click="initcommandUpdate(command, 'number')"
icon="pencil-alt"/>
</a>
</span>
<b-input-group v-else size="sm">
<b-form-input name="number"
v-model="updateValues[command.id+'_number']"
v-validate="'required|min:3'"
v-bind:class="{'is-danger': errors.has('name'), 'is-invalid': errors.has('name')}"
class="form-control" type="text"
:placeholder="'command number ('+command.number +')'"
@blur="updatecommand(command.id, 'number')"
@keyup.enter="updatecommand(command.id, 'number')"
required></b-form-input>
<b-input-group-append>
<b-button :disabled="errors.has('number')"
@click="updatecommand(command.id, 'number')"
variant="outline-success">
<font-awesome-icon icon="check"></font-awesome-icon>
</b-button>
</b-input-group-append>
</b-input-group>
<b-input-group v-else>
<b-form-input :id="command.id+'_alternative_name'" name="alternative_name"
v-model="updateValues[command.id+'_alternative_name']"
v-validate="'required|min:3'"
v-bind:class="{'is-danger': errors.has('alternative_name'), 'is-invalid': errors.has('alternative_name')}"
class="form-control" type="text"
:placeholder="'Alternative name ('+command.alternative_name +')'"
required></b-form-input>
<b-input-group-append>
<b-button :disabled="errors.has('alternative_name')"
@click="updateRecCommand(command.id, 'alternative_name')"
variant="outline-success">
<font-awesome-icon icon="check"></font-awesome-icon>
</b-button>
</b-input-group-append>
</b-input-group>
</small>
</p>
<p class="card-text">
<small><strong>{{ $t('comment') }}:</strong>&nbsp;
<span v-if="!formEditField[command.id+'_comment']">{{command.comment}}&nbsp;
<small><strong>{{ $t('description') }}:</strong>&nbsp;
<span v-if="!formEditField[command.id+'_description']">{{command.description}}&nbsp;
<a class="float-right badge badge-pill badge-info">
<font-awesome-icon
@click="initcommandUpdate(command, 'comment')"
@click="initRecCommandUpdate(command, 'description')"
icon="pencil-alt"/>
</a>
</span>
<textarea class="textarea form-control" v-else name="comment"
v-model="updateValues[command.id+'_comment']"
:placeholder="'Comment ('+command.comment +')'"
@blur="updatecommand(command.id, 'comment')"></textarea>
v-model="updateValues[command.id+'_description']"
:placeholder="'Comment ('+command.description +')'"
@blur="updateRecCommand(command.id, 'description')"></textarea>
</small>
</p>
<hr/>
<span v-if="!formEditField[command.id+'_recorder_id']">{{command.recorder_id}}&nbsp;
<div v-if="command.recorder">
<p class="card-text"><strong>{{ $t('Recorder') }}:</strong>&nbsp;{{command.recorder.name}}&nbsp;
({{command.recorder.ip}}) / ({{command.recorder.network_name}})</p>
<div v-if="command.recorder_model">
<p class="card-text"><strong>{{ $t('Recorder') }} {{ $t('model') }}:</strong>&nbsp;{{command.recorder_model.name}}&nbsp;</p>
</div>
<div v-else>
<p class="card-text"><strong>{{ $t('Recorder') }}:</strong>&nbsp;{{
$t('no_recorder_defined')}}</p>
$t('no_recorder_model_defined')}}</p>
</div>
<a class="float-right badge badge-pill badge-info">
<font-awesome-icon
@click="initcommandUpdate(command, 'recorder_id')" icon="pencil-alt"/>
</a>
</span>
<b-form v-else>
<b-input-group>
<select class="form-control" v-model="updateValues[command.id+'_recorder_id']">
<option value="">No recorder selected</option>
<option v-for="recorder in recorders" v-bind:value="recorder.id">
{{ recorder.name }}
</option>
</select>
<b-input-group-append>
<b-button :disabled="errors.has('recorder_id')"
@click="updatecommand(command.id, 'recorder_id')"
variant="outline-success">
<font-awesome-icon icon="check"></font-awesome-icon>
</b-button>
</b-input-group-append>
</b-input-group>
<div class="form-check">
<input class="form-check-input" type="checkbox"
v-model="show_assigned_recorders" id="defaultCheck1">
<label class="form-check-label" for="defaultCheck1">
Show already assigned recorders
</label>
</div>
</b-form>
</b-card-text>
<div slot="footer">
<small class="text-muted">
<p>{{ $t('created')}}: {{command.created_at | moment("dddd, MMMM Do YYYY")}}
<span class="pull-right">
<button type="button" v-on:click="deletecommand(command.id)"
class="btn btn-sm btn-danger">{{
$t('delete') }}&nbsp;<font-awesome-icon
icon="trash"/>
</button>
</span>
</p>
</small>
</div>
@@ -173,8 +93,8 @@
<b-tab title="Create command">
<template slot="title">
<font-awesome-icon icon="plus"/>
<i>{{$t('create')}}</i>&nbsp;<font-awesome-icon icon="door-open"/>
<strong>{{$t('command')}}</strong>
<i>{{$t('create')}}</i>&nbsp;<font-awesome-icon icon="cogs"/>
<strong>{{$t('virtual')}} {{$t('command')}}</strong>
</template>
<b-card-text>
<p>{{ $t('Create a new command')}}:</p>
@@ -287,6 +207,7 @@
import PulseLoader from 'vue-spinner/src/PulseLoader.vue';
import getRepository from '@/api/RepositoryFactory';
const recorderRepository = getRepository('recorder');
const commandRepository = getRepository('command');
export default {
@@ -310,11 +231,11 @@
};
},
methods: {
savecommand() {
saveCommand() {
this.$parent.$data.isLoading = true;
commandRepository.createcommand(this.form)
commandRepository.createCommand(this.form)
.then(() => {
this.$store.dispatch('loadcommands')
this.$store.dispatch('loadCommands')
.then(() => {
this.$parent.$data.isLoading = false;
this.tabIndex = 0;
@@ -324,33 +245,50 @@
this.$log.warn(msg);
});
},
initcommandUpdate(command, fieldName) {
initCommandUpdate(command, fieldName) {
this.$set(this.formEditField, command.id + '_' + fieldName, true);
this.$set(this.updateValues, command.id + '_' + fieldName, command[fieldName]);
},
updatecommand(id, fieldName) {
updateCommand(id, fieldName) {
this.$parent.$data.isLoading = true;
const data = {};
data[fieldName] = this.updateValues[id + '_' + fieldName];
commandRepository.updatecommand(id, data)
commandRepository.updateCommand(id, data)
.then(() => {
this.$store.dispatch('loadcommands')
this.$store.dispatch('loadCommands')
.then(() => {
this.$parent.$data.isLoading = false;
this.formEditField[id + '_' + fieldName] = false;
});
});
},
deletecommand(id) {
deleteCommand(id) {
this.$parent.$data.isLoading = true;
commandRepository.deletecommand(id)
commandRepository.deleteCommand(id)
.then(() => {
this.$store.dispatch('loadcommands')
this.$store.dispatch('loadCommands')
.then(() => {
this.$parent.$data.isLoading = false;
});
});
},
initRecCommandUpdate(command, fieldName) {
this.$set(this.formEditField, command.id + '_' + fieldName, true);
this.$set(this.updateValues, command.id + '_' + fieldName, command[fieldName]);
},
updateRecCommand(id, fieldName) {
this.$parent.$data.isLoading = true;
const data = {};
data[fieldName] = this.updateValues[id + '_' + fieldName];
recorderRepository.updateRecorderCommand(id, data)
.then(() => {
this.$store.dispatch('loadRecorderCommands')
.then(() => {
this.$parent.$data.isLoading = false;
this.formEditField[id + '_' + fieldName] = false;
});
});
},
showErrorMessage(msg) {
this.$parent.$data.isLoading = false;
this.$parent.$data.showAlert = true;