123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314 |
- <template>
- <div class='admin_categories'>
- <modal-window v-model='showAddModal'>
- <div
- class='admin_categories__modal__overlay'
- :class='{
- "admin_categories__modal__overlay--show": loading
- }'
- >
- <loading-icon></loading-icon>
- </div>
- <div class='admin_categories__modal'>
- <p class='admin_categories__modal__text'>Add a category</p>
- <fancy-input v-model='add.name' placeholder='Category name'></fancy-input>
- <input type='color' class='button button--color_input' v-model='add.color' />
- <div class='admin_categories__modal__buttons'>
- <button class='button button--modal' @click='toggleAddModal'>Cancel</button>
- <button class='button button--modal button--green' @click='addCategory'>Add category</button>
- </div>
- </div>
- </modal-window>
- <modal-window v-model='showEditModal'>
- <div
- class='admin_categories__modal__overlay'
- :class='{
- "admin_categories__modal__overlay--show": loading
- }'
- >
- <loading-icon></loading-icon>
- </div>
- <div class='admin_categories__modal'>
- <p class='admin_categories__modal__text'>Edit this category</p>
- <fancy-input v-model='edit.name' placeholder='Category name'></fancy-input>
- <input type='color' class='button button--color_input' v-model='edit.color' />
- <div class='admin_categories__modal__buttons'>
- <button class='button button--modal' @click='toggleEditModal(null)'>Cancel</button>
- <button class='button button--modal button--green' @click='editCategory'>Update category</button>
- </div>
- </div>
- </modal-window>
- <div class='admin_categories__categories'>
- <div class='admin_categories__text'>
- Hover to remove or edit a category. <br/>
- Removing a category will place any threads in that category into 'Other'
- </div>
- <transition-group name='slide'>
- <div
- class='admin_categories__category'
- v-for='(category, $index) in categories'
- :key='category'
- >
- <div class='admin_categories__category__actions_holder'>
- <div class='admin_categories__category__actions'>
- <div
- class='admin_categories__category__action'
- @click='removeCateogry(category.id, $index)'
- >Remove</div>
- <div
- class='admin_categories__category__action'
- @click='toggleEditModal(category, $index)'
- >Edit</div>
- </div>
- </div>
- <div
- class='admin_categories__category__color'
- :style='{ "background-color": category.color }'
- ></div>
- <div class='admin_categories__category__name'>{{category.name}}</div>
- </div>
- </transition-group>
- <div style="margin-top: 0.5rem;">
- <div class='admin_categories__category admin_categories__category--add' @click='toggleAddModal'>
- <div
- class='admin_categories__category__color fa fa-plus'
- >
- </div>
- <div class='admin_categories__category__name'>Add new category</div>
- </div>
- </div>
- </div>
- </div>
- </template>
- <script>
- import ModalWindow from './ModalWindow'
- import FancyInput from './FancyInput'
- import LoadingIcon from './LoadingIcon'
- import AjaxErrorHandler from '../assets/js/errorHandler'
- export default {
- name: 'AdminCategories',
- components: {
- ModalWindow,
- FancyInput,
- LoadingIcon
- },
- data () {
- return {
- loading: false,
- showAddModal: false,
- showEditModal: false,
-
- add: {
- name: '',
- color: '#ffffff'
- },
- edit: {
- name: '',
- color: '#ffffff',
- id: null,
- index: null
- },
- categories: []
- }
- },
- methods: {
- toggleAddModal () {
- this.add.name = ''
- this.add.color = '#ffffff'
- this.showAddModal = !this.showAddModal
- },
- toggleEditModal (category, index) {
- if(category) {
- this.edit.name = category.name
- this.edit.color = category.color
- this.edit.id = category.id
- this.edit.index = index
- } else {
- this.edit.name = ''
- this.edit.color = '#ffffff'
- this.edit.id = null
- this.edit.index = null
- }
-
- this.showEditModal = !this.showEditModal
- },
- addCategory () {
- this.loading = true
- this.axios
- .post('/api/v1/category', { name: this.add.name, color: this.add.color })
- .then(res => {
- this.toggleAddModal()
- this.loading = false
- this.categories.push(res.data)
- this.$store.commit('addCategories', res.data)
- })
- .catch(AjaxErrorHandler(this.$store))
- },
- removeCateogry (id, index) {
- this.axios
- .delete('/api/v1/category/' + id)
- .then(res => {
- this.categories.splice(index, 1)
- this.$store.commit('removeCategory', id)
- if(res.data.otherCategoryCreated) {
- this.$store.commit('addCategories', res.data.otherCategoryCreated)
- }
- })
- .catch(AjaxErrorHandler(this.$store))
- },
- editCategory () {
- this.loading = true
- this.axios
- .put('/api/v1/category/' + this.edit.id ,{
- name: this.edit.name,
- color: this.edit.color
- })
- .then(res => {
- this.loading = false
- this.categories.splice(this.edit.index, 1, res.data)
- this.$store.commit('updateCategory', res.data)
- this.toggleEditModal()
- })
- .catch(AjaxErrorHandler(this.$store))
- }
- },
- mounted () {
- this.axios
- .get('/api/v1/category')
- .then(res => {
- this.categories = res.data.filter(c => c.name !== 'Other')
- })
- .catch(AjaxErrorHandler(this.$store))
- }
- }
- </script>
- <style lang='scss' scoped>
- @import '../assets/scss/variables.scss';
- .slide-enter-active, .slide-leave-active, .slice-move {
- transition: all 1s;
- }
- .slide-enter, .slide-leave-to {
- opacity: 0;
- }
- .admin_categories {
- @at-root #{&}__modal {
- padding: 1rem;
- @at-root #{&}__text {
- margin-top: -0.5rem;
- margin-bottom: 1rem;
- }
- @at-root #{&}__buttons {
- margin-top: 0.5rem;
- }
- }
- @at-root #{&}__categories {
- background-color: #fff;
- padding: 1.5rem;
- border-radius: 0.25rem;
- @extend .shadow_border;
- }
- @at-root #{&}__text {
- margin-bottom: 1rem;
- }
- @at-root #{&}__category {
- display: inline-flex;
- position: relative;
- align-items: center;
- background-color: rgba($color__lightgray--primary, 0.5);
- justify-content: center;
- border-radius: 5rem;
- padding: 0.25rem 0.5rem 0.25rem 0.5rem;
- border: 0.1rem solid $color__gray--darker;
- margin-right: 0.5rem;
- margin-bottom: 0.5rem;
- transition: all 0.2s;
- cursor: default;
- &:hover {
- background-color: $color__lightgray--primary;
- & .admin_categories__category__actions_holder {
- opacity: 1;
- margin-top: 0;
- pointer-events: all;
- }
- }
- @at-root #{&}--add {
- top: -0.25rem;
- cursor: pointer;
- }
- @at-root #{&}__actions_holder {
- position: absolute;
- top: -2.25rem;
- opacity: 0;
- pointer-events: none;
- margin-top: 1rem;
- padding-bottom: 1rem;
- transition: all 0.2s;
- }
- @at-root #{&}__actions {
- border-radius: 3rem;
- border: 0.1rem solid $color__gray--darker;
- overflow: hidden;
- display: flex;
- background-color: #fff;
- box-shadow: 0 0.2rem 3px 0px rgba(224, 224, 224, 0.4);
- }
- @at-root #{&}__action {
- padding: 0.25rem 0.5rem;
- cursor: pointer;
- transition: all 0.2s;
- &:first-of-type {
- border-right: 0.1rem solid $color__gray--primary;
- }
- &:hover {
- background-color: $color__lightgray--primary;
- }
- }
- @at-root #{&}__color {
- height: 1.25rem;
- width: 1.25rem;
- border-radius: 100%;
- margin-left: 0rem;
- margin-right: 0.25rem;
- display: flex;
- align-items: center;
- justify-content: center;
- }
- @at-root #{&}__name {
- position: relative;
- bottom: 0.1rem;
- }
- }
- }
- </style>
|