Skip to content
This repository has been archived by the owner on Jan 2, 2024. It is now read-only.

Commit

Permalink
Format patron names (#119)
Browse files Browse the repository at this point in the history
* Extract capitalize() into new core util

Was never crazy about initial implementation as page component method.

This is a modest start to extracting a common core (#109) and will prove
immediately useful in formatting patron names.

* Consistent formatting for patron names

Uppercase for first letter. Lowercase for the rest.

> Even though it might result in false formatting for edge cases,
preferable over haphazard look when patrons enter all upper or lower.
  • Loading branch information
cappadona committed Mar 22, 2019
1 parent 7f4c21f commit f1db73b
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 7 deletions.
10 changes: 3 additions & 7 deletions pages/_location/spaces/_category.vue
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,16 @@
<script>
import moment from 'moment'
import { mapState } from 'vuex'
import signage from '~/utils/core'
import labStats from '~/utils/labstats'
import libCal from '~/utils/libcal'
import SpaceAvailability from '~/components/SpaceAvailability'
export default {
head () {
return {
title: this.capitalize(this.$route.params.category),
titleTemplate: this.capitalize(this.$route.params.location) + ' - %s',
title: signage.capitalize(this.$route.params.category),
titleTemplate: signage.capitalize(this.$route.params.location) + ' - %s',
link: [
{ rel: 'stylesheet', href: 'https://fonts.googleapis.com/css?family=Lato:300,400,700' },
// TODO: Use packages for officiaal Vue.js component
Expand Down Expand Up @@ -109,11 +110,6 @@ export default {
category: this.$route.params.category
})
}, 1000 * 60)
},
methods: {
capitalize (string) {
return string.charAt(0).toUpperCase() + string.slice(1)
}
}
}
</script>
Expand Down
7 changes: 7 additions & 0 deletions utils/core.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
const core = {
capitalize: function (string) {
return string.charAt(0).toUpperCase() + string.slice(1)
}
}

export default core
12 changes: 12 additions & 0 deletions utils/libcal.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import schema from '~/utils/schema'
import signage from '~/utils/core'
import _ from 'lodash'
import moment from 'moment'
import nanoid from 'nanoid'
Expand Down Expand Up @@ -128,6 +129,14 @@ const libCal = {
}
return true
})
// Consistent formatting for patron names
// -- even though it might result in false formatting for edge cases, preferable
// -- over haphazard look when patrons enter all upper or lower
.map(b => {
b.firstName = libCal.formatPatronName(b.firstName)
b.lastName = libCal.formatPatronName(b.lastName)
return b
})
// Fill gaps between & pad bookings with available slots
.flatMap(function (booking, index, allBookings) {
const paddedBooking = [booking]
Expand Down Expand Up @@ -191,6 +200,9 @@ const libCal = {
formatDate: function (date) {
return moment(date).format('Y-MM-DD')
},
formatPatronName: function (name) {
return signage.capitalize(name.toLowerCase())
},
formatStatusChange: function (datetime) {
const statusChange = datetime === null ? 'no upcoming openings' : moment(datetime).calendar()
return statusChange === '12:00 am' ? 'Midnight' : statusChange
Expand Down

0 comments on commit f1db73b

Please sign in to comment.