397 lines
14 KiB
Vue
397 lines
14 KiB
Vue
<template>
|
|
<div class="plannings">
|
|
<div class="row justify-content-center">
|
|
<div class="col-1 text-center">
|
|
<a class="sticky-top btn btn-primary mt-5" @click="goToPlanning(false)">←</a>
|
|
</div>
|
|
|
|
<div class="col-10">
|
|
<table class="table table-bordered align-middle text-center">
|
|
<thead>
|
|
<tr>
|
|
<th rowspan="2" colspan="2">
|
|
|
|
</th>
|
|
<th colspan="5" v-for="item in weeksCells" class="Mon Fri">
|
|
S {{item.num}} - {{item.month}} {{item.year}}
|
|
</th>
|
|
</tr>
|
|
<tr>
|
|
<th v-for="day in days" :class="'day '+day.eday">
|
|
{{day.day}} {{day.num}}
|
|
</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
<template v-for="(user,index) in schedules">
|
|
<tr v-for="(slot,key) in user">
|
|
<th rowspan="4" colspan="2" v-if="key == 1">
|
|
{{users[index].name}}
|
|
</th>
|
|
<td v-for="day in days" :class="'dynCell day '+user[key][day.key].type.value+ ' ' +day.eday">
|
|
{{user[key][day.key]['text']}}
|
|
<button class="btn btn-edit" type="button" data-bs-toggle="modal"
|
|
data-bs-target="#editModal" @click="setModalData(user[key][day.key]['id'])">✎</button>
|
|
<button class="btn btn-clear" @click="eraseCell(user[key][day.key]['id'])">⌫</button>
|
|
</td>
|
|
</tr>
|
|
</template>
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
|
|
|
|
<div :class="'col-10 grid-week grid-'+weeksCells.length+'week'">
|
|
<!--line header 1 -->
|
|
<div class="empty"></div>
|
|
<div class="week" v-for="item in weeksCells">
|
|
S {{item.num}} - {{item.month}} {{item.year}}
|
|
</div>
|
|
<!--line header 2 -->
|
|
<div v-for="day in days" :class="'day '+day.eday">
|
|
{{day.day}} {{day.num}}
|
|
</div>
|
|
<template v-for="(user,index) in schedules">
|
|
<div class="name">{{users[index].name}}</div>
|
|
<template v-for="(slot,key) in user">
|
|
<div v-for="day in days" :class="'day '+user[key][day.key].type.value+ ' ' +day.eday">
|
|
{{user[key][day.key]['text']}}
|
|
</div>
|
|
</template>
|
|
</template>
|
|
</div>
|
|
<div class="col-1 text-center">
|
|
<a class="sticky-top btn btn-primary mt-5" @click="goToPlanning(true)">→</a>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- Modal -->
|
|
<div v-if="currentWeek" class="modal fade" id="editModal" tabindex="-1" aria-labelledby="modalLabel" aria-hidden="true" >
|
|
<div class="modal-dialog modal-lg">
|
|
<div class="modal-content">
|
|
<div class="modal-header">
|
|
<h5 class="modal-title" id="modalLabel" ref="modalLabel">Modal title</h5>
|
|
<button ref="close" type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close" ></button>
|
|
</div>
|
|
<div class="modal-body">
|
|
<div class="container">
|
|
<div class="row justify-content-center">
|
|
<div v-if="error" class="alert alert-danger" role="alert">
|
|
{{ error }}
|
|
</div>
|
|
<div class="col-8">
|
|
<div class="form-group mb-3">
|
|
<label :for="'type'+currentWeek.id" class="col-form-label text-md-right ms-5">Categorie</label>
|
|
<select :id="'type'+currentWeek.id" ref="type" class="form-select" aria-label="Sélectionnez une catégorie">
|
|
<option value="" :selected="!currentType">Sélectionnez une catégorie</option>
|
|
<option v-for="type in types" :key="type.value" :value="type.value"
|
|
:selected="type.value === currentType"
|
|
:style="'background-color:'+ type.value+';'">{{ type.label }}</option>
|
|
</select>
|
|
</div>
|
|
<div class="form-group mb-3">
|
|
<label :for="'morph'+currentWeek.id" class="col-form-label text-md-right ms-5">Type d'élément lié</label>
|
|
<select :id="'morph'+currentWeek.id" ref="morph" class="form-select" @change="selectChange" aria-label="Sélectionnez un élément à lier">
|
|
<option value="" :selected="!currentModel">Sélectionnez un élément à lier</option>
|
|
<option v-for="model in models" :key="model.value" :selected="model.value === currentModel" :value="model.value">{{ model.label }}</option>
|
|
</select>
|
|
</div>
|
|
<div class="form-group mb-3" v-if="dDisplay">
|
|
<label :for="'select'+currentWeek.id" class="col-form-label text-md-right ms-5">Élément lié</label>
|
|
<v-select
|
|
:id="'select'+currentWeek.id"
|
|
ref="select"
|
|
:loading="loading"
|
|
v-model="value"
|
|
:clearable="false"
|
|
label="label"
|
|
:options='data'
|
|
@search="search"
|
|
:disabled="dReadonly||dDisabled"
|
|
:filterable="true"
|
|
:searchable="true">
|
|
<li slot="list-footer" class="pagination">
|
|
<button
|
|
@click="$event.preventDefault(); page -= 1"
|
|
:disabled="!hasPrevPage"
|
|
class="btn btn-sm btn-primary mt-2 mb-2 ms-2 me-2">Précédent</button>
|
|
<button
|
|
@click="$event.preventDefault(); page += 1"
|
|
:disabled="!hasNextPage"
|
|
class="btn btn-sm btn-primary mt-2 mb-2">Suivant</button>
|
|
</li>
|
|
</v-select>
|
|
</div>
|
|
<div class="form-group mb-3">
|
|
<label :for="'text'+currentWeek.id" class="col-form-label text-md-right ms-5">Description courte</label>
|
|
<textarea ref="text" class="form-control" name="text"
|
|
:id="'text'+currentWeek.id" rows="2" placeholder="" @keydown="limitLines($event)" ></textarea>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<div class="row justify-content-center">
|
|
<div class="col-8 text-center">
|
|
<button class="btn btn-primary me-3" @click="saveCell()">Valider</button>
|
|
<button class="btn btn-danger" @click="$refs.close.click()">Fermer</button>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
|
|
|
|
</div>
|
|
</template>
|
|
|
|
<script>
|
|
export default {
|
|
props: {
|
|
dbSchedules: {
|
|
type: String,
|
|
},
|
|
dbUsers: {
|
|
type: String,
|
|
},
|
|
weeks: {
|
|
type: String,
|
|
},
|
|
browseDate: {
|
|
type: String,
|
|
default: function() {
|
|
return new Date();
|
|
}
|
|
},
|
|
},
|
|
mounted() {
|
|
this.currentDate = JSON.parse(this.browseDate);
|
|
this.weeksCells = JSON.parse(this.weeks);
|
|
this.numweeks = this.weeksCells.length;
|
|
this.days = this.prepareDays();
|
|
this.users = JSON.parse(this.dbUsers);
|
|
this.schedules = this.prepareSched(JSON.parse(this.dbSchedules));
|
|
},
|
|
data() {
|
|
return {
|
|
currentDate: null,
|
|
weeksCells: [],
|
|
days: [],
|
|
users:[],
|
|
schedules: [],
|
|
};
|
|
},
|
|
watch: {
|
|
},
|
|
methods: {
|
|
goToPlanning(forward) {
|
|
console.log(forward);
|
|
let date = this.moment(this.currentDate).startOf('week').subtract(7, 'day');
|
|
if(forward) {
|
|
date = this.moment(this.currentDate).add(7, 'day')
|
|
}
|
|
let url = new URL(this.route('schedule.index'))
|
|
location = url.origin+ url.pathname + '?p='+date.format('DD/MM/YYYY')
|
|
},
|
|
prepareDays() {
|
|
let mydays = [];
|
|
for(let i=0; i < this.numweeks * 7; i++) {
|
|
let date = this.moment(this.currentDate).add(i, 'day');
|
|
let obj = {
|
|
day: date.format('ddd'),
|
|
num: date.format('DD'),
|
|
eday: date.locale("en").format('ddd'),
|
|
key: date.format('DD/MM/YYYY'),
|
|
}
|
|
mydays.push(obj);
|
|
if(date.day() == 5) {
|
|
i+=2;
|
|
}
|
|
}
|
|
return mydays;
|
|
},
|
|
prepareSched(dbscheds) {
|
|
var templateObj = {"type":{"label":"","value":""},"text":"","id_lie":null,"model_lie":null,"id":null}
|
|
//we need to make missing users
|
|
Object.keys(this.users).forEach(id => {
|
|
if(dbscheds[id] === undefined) {
|
|
dbscheds[id] = {};
|
|
}
|
|
});
|
|
Object.keys(dbscheds).forEach(userid => {
|
|
//what if we missing a slot for the whole period ?
|
|
//we need to make missing slots too
|
|
for(let i=1; i < 5; i++) {
|
|
if(dbscheds[userid][i] === undefined) {
|
|
dbscheds[userid][i] = {};
|
|
}
|
|
}
|
|
Object.keys(dbscheds[userid]).forEach(slotkey => {
|
|
this.days.forEach(day => {
|
|
if(dbscheds[userid][slotkey][day.key] === undefined) {
|
|
//console.log('need ' + day.key + ' for slot ' + slotkey + ' for user ' + userid);
|
|
dbscheds[userid][slotkey][day.key] = templateObj;
|
|
}
|
|
});
|
|
});
|
|
});
|
|
return dbscheds;
|
|
},
|
|
setModalData(id) {
|
|
console.log(id);
|
|
},
|
|
eraseCell(id) {
|
|
|
|
}
|
|
}
|
|
};
|
|
</script>
|
|
|
|
<style lang="scss">
|
|
@import "vue-select/src/scss/vue-select.scss";
|
|
.plannings {
|
|
.sticky-top {
|
|
top: 20rem !important;
|
|
}
|
|
}
|
|
.grid-1week {
|
|
display: grid;
|
|
grid-template-columns: 2fr repeat(5, 1fr);
|
|
grid-auto-rows: minmax(50px, auto);
|
|
}
|
|
.grid-2week {
|
|
display: grid;
|
|
grid-template-columns: 2fr repeat(10, 1fr);
|
|
grid-auto-rows: minmax(50px, auto);
|
|
align-items: center;
|
|
}
|
|
.grid-week div {
|
|
border-width:0 1px 1px 0;
|
|
border-style: solid;
|
|
border-color: var(--bs-cyan);
|
|
display: flex;
|
|
justify-content: center;
|
|
align-self: stretch;
|
|
align-items: center;
|
|
}
|
|
.empty {
|
|
grid-column: auto;
|
|
grid-row: auto /span 2;
|
|
}
|
|
.week {
|
|
grid-column: auto /span 5;
|
|
grid-row: auto;
|
|
}
|
|
.name {
|
|
grid-column: auto;
|
|
grid-row: auto /span 4;
|
|
}
|
|
|
|
table {
|
|
.Mon {
|
|
border-left: 4px solid;
|
|
}
|
|
.Fri {
|
|
border-right: 4px solid;
|
|
}
|
|
}
|
|
|
|
.dynCell.day {
|
|
position: relative;
|
|
&:hover .btn {
|
|
opacity: 1;
|
|
}
|
|
$buttonBgColor: #4d4d4d;
|
|
|
|
// Reset button Style to nice one
|
|
button {
|
|
display: inline;
|
|
border: none;
|
|
padding: 0.6rem 3rem;
|
|
margin: 0;
|
|
text-decoration: none;
|
|
background: $buttonBgColor;
|
|
font-size: 1rem;
|
|
cursor: pointer;
|
|
text-align: center;
|
|
transition: background 250ms ease-in-out, transform 150ms ease;
|
|
-webkit-appearance: none;
|
|
-moz-appearance: none;
|
|
}
|
|
|
|
button:disabled,
|
|
button[disabled] {
|
|
color: #aaa;
|
|
}
|
|
|
|
button:hover,
|
|
button:focus {
|
|
background: darken($buttonBgColor, 10%);
|
|
}
|
|
|
|
button:focus {
|
|
outline: 1px solid #fff;
|
|
outline-offset: -4px;
|
|
}
|
|
|
|
button:active {
|
|
transform: scale(0.99);
|
|
}
|
|
|
|
.btn {
|
|
position: absolute;
|
|
top: 0.1rem;
|
|
right: 0.1rem;
|
|
padding: 0;
|
|
width: 1.8rem;
|
|
height: 1.8rem;
|
|
margin: 0;
|
|
background-color: $buttonBgColor;
|
|
opacity: 0;
|
|
transition: 200ms opacity;
|
|
&.hide {
|
|
opacity: 0 !important;
|
|
}
|
|
&:hover,
|
|
&:focus {
|
|
background-color: darken($buttonBgColor, 10%);
|
|
}
|
|
&.btn-clear {
|
|
color: darken($color: #fff, $amount: 5);
|
|
}
|
|
&:nth-last-child(2) {
|
|
right: inherit;
|
|
left: 0.1rem;
|
|
}
|
|
&:nth-last-child(3) {
|
|
right: inherit;
|
|
top: 2.1rem;
|
|
left: 0.1rem;
|
|
}
|
|
&:nth-last-child(1) {
|
|
top: 2.1rem;
|
|
right: 0.1rem;
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
@import "toastify-js/src/toastify.css";
|
|
@import "vue-select/src/scss/vue-select.scss";
|
|
.planning {
|
|
overflow: auto;
|
|
|
|
td {
|
|
height: 50px;
|
|
}
|
|
|
|
#text {
|
|
height: 5.5rem;
|
|
padding: 1rem 2rem;
|
|
resize: none;
|
|
width: 37rem;
|
|
margin: 0 auto;
|
|
}
|
|
}
|
|
</style>
|