Commit 944fe373 authored by Jarod Owen's avatar Jarod Owen
Browse files

Schedules, Overrides, About Page and API rout changes.

parent bf40da39
This diff is collapsed.
......@@ -19,8 +19,8 @@
"bootstrap": "^4.4.1",
"bootswatch": "^4.4.1",
"core-js": "^3.6.4",
"jquery": "^3.4.1",
"node-sass": "^4.13.1",
"jquery": "^3.5.1",
"node-sass": "^4.14.1",
"popper.js": "^1.16.1",
"rrule": "^2.6.4",
"v-calendar": "^1.0.0-beta.23",
......
......@@ -3,17 +3,66 @@
<h1>Kretschmar Hall Doorcode System</h1>
<div id="nav">
<router-link to="/">Home</router-link> |
<router-link to="/about">About</router-link> |
<router-link to="/user">Users</router-link> |
<router-link to="/userG">Groups</router-link> |
<router-link to="/door">Doors</router-link> |
<router-link to="/event">Events</router-link> |
<router-link to="/log">Log</router-link>
<router-link to="/about">About</router-link><br /><br />
<router-link v-if="loggedIn() & logIn" to="/me">My Info</router-link>
<span v-if="perms.includes('manage-users')">
| <router-link to="/user">Users</router-link>
</span>
<span v-if="perms.includes('manage-groups')">
| <router-link to="/userG">Groups</router-link>
</span>
<span v-if="perms.includes('manage-doors')">
| <router-link to="/door">Doors</router-link>
</span>
<span v-if="perms.includes('manage-groups')">
| <router-link to="/event">Events</router-link>
</span>
<span v-if="perms.includes('logs-read')">
| <router-link to="/log">Log</router-link>
</span>
</div>
<router-view/>
</div>
</template>
<script>
import axios from 'axios'
import constants from './constants'
export default {
mounted () {
axios.get(constants.APIHOST + '/me/permissions')
.then(response => {
var per = response.data.permissions
console.log(per)
this.perms = per
})
.catch(error => {
console.log(error.response)
})
},
data () {
return {
perms: [],
logIn: false,
dummy: null
}
},
methods: {
loggedIn () {
axios.get(constants.APIHOST + '/me')
.then(response => {
this.logIn = true
})
.catch(error => {
this.dummy = error
this.logIn = false
})
return true
}
}
}
</script>
<style lang="scss">
#app {
font-family: Avenir, Helvetica, Arial, sans-serif;
......@@ -60,7 +109,7 @@
right: 3px
.adjust-2
position: relative
left: 27px
left: 139px
.adjust-3
position: relative
top: 3px
......@@ -76,6 +125,28 @@
.adjust-7
position: relative
left: 6px
.adjust-8
position: relative
top: 3%
.adjust-9
position: relative
top: 2px
.adjust-10
position: relative
left: 12px
.adjust-11
position: relative
top: 16px
.textRow
margin-bottom: 4px
.narrow-1
width: 75%
.radBoxLab
margin:
left: 3px
right: 9px
.chkRow
margin-bottom: 25px
.ovrdLabel
margin-bottom: 8px
</style>
......@@ -50,7 +50,7 @@ export default {
mounted () {
axios.get(constants.APIHOST + '/groups')
.then(response => {
var grps = response.data.groups
var grps = response.data.data
console.log(grps)
for (const i in grps) {
this.groups.push(grps[i].title)
......
......@@ -29,31 +29,78 @@
</div>
<div class="col-4"></div>
</div>
<div class="row">
<div class="col">Overrides: NYI</div>
</div>
<div class="btn-group adjust-4">
<button class="btn btn-primary rounded-left" @click="$emit('cancel')">Cancel</button>
<button class="btn btn-primary" @click="update()">Update</button>
<button class="btn btn-primary rounded-right" @click="del()">Delete</button>
<div class="adjust-11">
<div class="row ovrdLabel textRow">
<div class="col">
<input id="DEOver" class="adjust-8" type="checkbox" v-model="override" />
<label for="DEOver" class="radBoxLab">Override</label>
</div>
</div>
<div class="row textRow" v-if="override">
<div class="col text-right">Type:</div>
<div class="col-3 text-left">
<input class="adjust-8" id="DERadTL" type="radio" name="type" :value="1" v-model="type">
<label class="radBoxLab" for="DERadTL">Closed Mode</label>
<input class="adjust-8" id="DERadTOM" type="radio" name="type" :value="0" v-model="type">
<label class="radBoxLab" for="DERadTOM">Open Mode</label>
</div>
<div class="col-4"></div>
</div>
<div class="row textRow" v-if="override">
<div class="col text-right">
<label class="adjust-4">Start:</label>
</div>
<div class="col-3 text-left">
<v-date-picker v-model="startDate"></v-date-picker>
<vue-timepicker v-model="startTime" :minute-interval="5"
format="hh:mm A"></vue-timepicker>
</div>
<div class="col-4"></div>
</div>
<div class="row textRow" v-if="override">
<div class="col text-right">
<label class="adjust-4">End:</label>
</div>
<div class="col-3 text-left">
<v-date-picker v-model="endDate"></v-date-picker>
<vue-timepicker v-model="endTime" :minute-interval="5"
format="hh:mm A"></vue-timepicker>
</div>
<div class="col-4"></div>
</div>
<div class="row ovrdLabel textRow" v-if="override">
<div class="col text-right">
<label for="DEReason" class="adjust-4">Reason:</label>
</div>
<div class="col-3 text-left">
<input id="DEReason" class="form-control" type="text" v-model="reason" />
</div>
<div class="col-4"></div>
</div>
<div class="btn-group adjust-4">
<button class="btn btn-primary rounded-left" @click="$emit('cancel')">Cancel</button>
<button class="btn btn-primary" @click="update()">Update</button>
<button class="btn btn-primary rounded-right" @click="del()">Delete</button>
</div>
</div><br /><br /><br /><br /><br /><br /><br /><br /><br /><br />
</div>
</template>
<script>
import Multiselect from 'vue-multiselect'
import VueTimepicker from 'vue2-timepicker'
import axios from 'axios'
import constants from '../constants'
export default {
components: { Multiselect },
components: { Multiselect, VueTimepicker },
mounted () {
axios.get(constants.APIHOST + '/groups')
.then(response => {
console.log('mounted', response.data.groups[0])
for (const i in response.data.groups) {
this.groups.push(response.data.groups[i].title)
this.groupIds.push(response.data.groups[i].id)
console.log('mounted', response.data.data[0])
for (const i in response.data.data) {
this.groups.push(response.data.data[i].title)
this.groupIds.push(response.data.data[i].id)
}
})
.catch(error => {
......@@ -65,18 +112,40 @@ export default {
var retBef = []
axios.get(constants.APIHOST + '/doors/' + this.info.id + '/groups')
.then(response => {
console.log('getGroups', response.data.groups)
resp = response.data.groups
console.log('getGroups', response.data.data)
resp = response.data.data
for (const i in resp) {
retSel.push(resp[i].title)
retBef.push(resp[i].id)
}
this.selGroup = retSel
this.groupsBefore = retBef
console.log('selGroup', this.selGroup)
})
.catch(error => {
console.log('getGroups', error)
})
axios.get(constants.APIHOST + '/overrides/', { params: { door_id: this.info.id } })
.then(response => {
console.log('overrides', response)
var over = response.data.data
if (over !== []) {
console.log(over)
this.override = true
this.overrideB4 = true
this.overID = over[0].id
this.reason = over[0].reason
this.type = over[0].type
this.startDate = this.dateParser(over[0].start)
this.startTime = this.timeParser(this.startDate)
this.endDate = this.dateParser(over[0].end)
this.endTime = this.timeParser(this.endDate)
}
})
.catch(error => {
console.log(error)
})
},
props: ['info'],
data () {
......@@ -86,7 +155,24 @@ export default {
groups: [],
groupIds: [],
selGroup: [],
groupsBefore: []
groupsBefore: [],
overID: null,
override: false,
overrideB4: false,
startDate: new Date(),
endDate: new Date(),
startTime: {
hh: '',
mm: '',
A: ''
},
endTime: {
hh: '',
mm: '',
A: ''
},
type: 1,
reason: ''
}
},
methods: {
......@@ -98,12 +184,12 @@ export default {
if (this.nom !== '') {
sub.name = this.nom
}
axios.put(constants.APIHOST + '/doors/' + this.info.id, sub)
axios.patch(constants.APIHOST + '/doors/' + this.info.id, sub)
.then(response => {
console.log(response)
console.log('patch', response)
})
.catch(error => {
console.log(this.info.id, error)
console.log(error)
})
var groupsAfter = []
var removeFrom = []
......@@ -141,7 +227,107 @@ export default {
console.log('update: add', error)
})
}
this.$emit('cancel')
if (this.override === this.overrideB4) {
console.log('same')
if (this.override) {
console.log('true')
const sTime = this.revTimeParser(this.startTime)
const eTime = this.revTimeParser(this.endTime)
const sDt = new Date(this.startDate.getTime())
sDt.setHours(sTime[0], sTime[1], 0)
const eDt = new Date(this.endDate.getTime())
eDt.setHours(eTime[0], eTime[1], 0)
axios.patch(constants.APIHOST + '/overrides/' + this.overID,
{ start: sDt, end: eDt, reason: this.reason })
.then(response => {
console.log('overrideUpdate', response)
})
.catch(error => {
console.log('overrideUpdate err', error)
})
}
} else {
console.log('different')
if (this.override) {
const sTime = this.revTimeParser(this.startTime)
const eTime = this.revTimeParser(this.endTime)
const sDt = new Date(this.startDate.getTime())
sDt.setHours(sTime[0], sTime[1], 0)
const eDt = new Date(this.endDate.getTime())
eDt.setHours(eTime[0], eTime[1], 0)
axios.post(constants.APIHOST + '/overrides/',
{ start: sDt, end: eDt, reason: this.reason, door_id: this.info.id, type: this.type })
.then(response => {
console.log('overrideCreate', response)
})
.catch(error => {
console.log('overrideCreate err', error)
})
} else {
console.log('false')
const sTime = this.revTimeParser(this.startTime)
const sDt = new Date(this.startDate.getTime())
sDt.setHours(sTime[0], sTime[1], 0)
const eDt = new Date()
axios.patch(constants.APIHOST + '/overrides/' + this.overID, { start: sDt, end: eDt })
.then(response => {
console.log('overrideDel', response)
})
.catch(error => {
console.log('overrideDel err', error)
})
}
}
// this.$emit('cancel')
},
timeParser: function (t) {
console.log(t, 'parser')
var outTime = {
hh: '',
mm: '',
A: ''
}
var hrs = t.getHours()
var ampm = 'AM'
if (hrs === 0) {
hrs = '12'
} else if (hrs < 10) {
hrs = '0' + String(hrs)
} else if (hrs > 12) {
hrs = hrs - 12
if (hrs < 10) {
hrs = '0' + String(hrs)
} else {
hrs = String(hrs)
}
ampm = 'PM'
} else if (hrs === 12) {
hrs = String(hrs)
ampm = 'PM'
}
outTime.hh = hrs
if (t.getMinutes() < 10) {
outTime.mm = '0' + String(t.getMinutes())
} else {
outTime.mm = String(t.getMinutes())
}
outTime.A = ampm
return outTime
},
revTimeParser: function (t) {
console.log(t, 'revParser')
var outTime = []
var hrs = t.hh
var ampm = t.A
if (+hrs === 12 && ampm === 'AM') {
hrs = 0
} else if (+hrs < 12 && ampm === 'PM') {
hrs = +hrs + 12
}
outTime[0] = hrs
outTime[1] = t.mm
return outTime
},
del: function () {
if (confirm('Are you sure you want to delete ' + this.info.name + '?')) {
......@@ -154,6 +340,11 @@ export default {
})
this.$emit('cancel')
}
},
dateParser: function (s) {
// Credit to RobG of stackoverflow for this function
var b = s.split(/\D+/)
return new Date(Date.UTC(b[0], --b[1], b[2], b[3], b[4], b[5], b[6]))
}
}
}
......
<template>
<tr>
<td>{{ num }}</td><td>{{ name }}</td><td>NYI</td>
<!--<td><font-awesome-icons
data-toggle="tooltip"
data-placement="top"
:title="statusT()"
:icon="statusI()"
></font-awesome-icon></td>--><td>NYI</td>
<td><font-awesome-icon
data-toggle="tooltip"
data-placement="top"
......
......@@ -74,16 +74,16 @@ export default {
this.d2.setDate(this.d1.getDate() - 7)
var startDate = this.d2.toISOString()
var endDate = this.d1.toISOString()
axios.get(constants.APIHOST + '/doors/' + this.id + '/entries/', { params: { start: startDate, end: endDate } })
axios.get(constants.APIHOST + '/entries/', { params: { door_id: this.id, start: startDate, end: endDate } })
.then(response => {
this.entries = response.data.entries
this.entries = response.data.data
})
.catch(error => {
console.log('Entries', error)
})
axios.get(constants.APIHOST + '/doors/' + this.id + '/attempts/', { params: { start: startDate, end: endDate } })
axios.get(constants.APIHOST + '/attempts/', { params: { door_id: this.id, start: startDate, end: endDate } })
.then(response => {
this.attempts = response.data.attempts
this.attempts = response.data.data
})
.catch(error => {
console.log('Attempts', error)
......@@ -119,17 +119,17 @@ export default {
filter: function () {
var startDate = this.d2.toISOString()
var endDate = this.d1.toISOString()
axios.get(constants.APIHOST + '/doors/' + this.id + '/entries/', { params: { start: startDate, end: endDate } })
axios.get(constants.APIHOST + '/entries/', { params: { door_id: this.id, start: startDate, end: endDate } })
.then(response => {
console.log('Entries', response)
this.entries = response.data.entries
this.entries = response.data.data
})
.catch(error => {
console.log('Entries', error)
})
axios.get(constants.APIHOST + '/doors/' + this.id + '/attempts/', { params: { start: startDate, end: endDate } })
axios.get(constants.APIHOST + '/attempts/', { params: { door_id: this.id, start: startDate, end: endDate } })
.then(response => {
this.attempts = response.data.attempts
this.attempts = response.data.data
})
.catch(error => {
console.log('Attempts', error)
......
......@@ -13,7 +13,7 @@
<thead>
<tr>
<th>Location</th><th>Name</th><th>Last Access</th>
<th>Status</th><th>Edit</th><th>History</th>
<th>Edit</th><th>History</th>
</tr>
</thead>
<tbody>
......
This diff is collapsed.
This diff is collapsed.
<template>
<tr>
<td>{{ groupName }}</td>
<td>{{ typeNames[type] }}</td>
<td>{{ startFormDate }}</td>
<td>{{ timeForm }}</td>
<td>{{ endFormDate }}</td>
<td><font-awesome-icon
data-toggle="tooltip"
data-placement="top"
:title="'Edit'"
class="edit"
:icon="['fas', 'edit']"
@click="$emit('edit', id)"
></font-awesome-icon></td>
</tr>
</template>
<script>
/* eslint-disable vue/no-unused-components */
import { library } from '@fortawesome/fontawesome-svg-core'
import { faEdit, faHistory, faCheckCircle, faTimesCircle } from '@fortawesome/free-solid-svg-icons'
import { FontAwesomeIcon } from '@fortawesome/vue-fontawesome'
import axios from 'axios'
import constants from '../constants'
library.add(faEdit)
library.add(faHistory)
library.add(faCheckCircle)
library.add(faTimesCircle)
export default {
props: ['id', 'group_id', 'type', 'start_date', 'end_date', 'until', 'duration'],
components: { library, faEdit, faHistory, FontAwesomeIcon, axios },
mounted () {
axios.get(constants.APIHOST + '/groups/' + this.group_id)
.then(response => {
this.groupName = response.data.group.title
})
.catch(error => {
console.log(error)
})
var sDt = this.dateParser(this.start_date)
this.startFormDate = this.dateFormer(sDt)
this.timeForm = this.timeParser(sDt)
var eTimeDt = new Date()
eTimeDt.setTime(sDt.getTime() + this.duration) // * 1000
this.timeForm += ' - ' + this.timeParser(eTimeDt)
if (this.until === null) {
this.endFormDate = '(Endless)'
} else {
var eDt = new Date(Date.UTC(this.until.substring(0, 4),
Number(this.until.substring(4, 6)) - 1,
this.until.substring(6, 8),
this.until.substring(9, 11),
this.until.substring(11, 13)))
console.log(eDt)
this.endFormDate = this.dateFormer(eDt)
}
},
data () {
return {
groupName: '',
monthAbbr: ['Jan', 'Feb', 'Mar',
'Apr', 'May', 'Jun',
'Jul', 'Aug', 'Sep',
'Oct', 'Nov', 'Dec'],
typeNames: ['Open Mode', 'User Access'],
startFormDate: '',
endFormDate: '',
timeForm: ''
}
},
methods: {
dateParser: function (s) {
// Credit to RobG of stackoverflow for this function
var b = s.split(/\D+/)
return new Date(Date.UTC(b[0], --b[1], b[2], b[3], b[4], b[5], b[6]))
},
dateFormer: function (dt) {
var formDt = ''
formDt = dt.getDate() + ' ' +
this.monthAbbr[dt.getMonth()] + ' ' +
dt.getFullYear()