init crater

This commit is contained in:
Mohit Panjwani
2019-11-11 12:16:00 +05:30
commit bdf2ba51d6
668 changed files with 158503 additions and 0 deletions

View File

@ -0,0 +1,92 @@
import * as types from './mutation-types'
export const fetchItems = ({ commit, dispatch, state }, params) => {
return new Promise((resolve, reject) => {
window.axios.get(`/api/items`, {params}).then((response) => {
commit(types.BOOTSTRAP_ITEMS, response.data.items.data)
commit(types.SET_TOTAL_ITEMS, response.data.items.total)
resolve(response)
}).catch((err) => {
reject(err)
})
})
}
export const fetchItem = ({ commit, dispatch }, id) => {
return new Promise((resolve, reject) => {
window.axios.get(`/api/items/${id}/edit`).then((response) => {
resolve(response)
}).catch((err) => {
reject(err)
})
})
}
export const addItem = ({ commit, dispatch, state }, data) => {
return new Promise((resolve, reject) => {
window.axios.post('/api/items', data).then((response) => {
commit(types.ADD_ITEM, response.data)
resolve(response)
}).catch((err) => {
reject(err)
})
})
}
export const updateItem = ({ commit, dispatch, state }, data) => {
return new Promise((resolve, reject) => {
window.axios.put(`/api/items/${data.id}`, data).then((response) => {
commit(types.UPDATE_ITEM, response.data)
resolve(response)
}).catch((err) => {
reject(err)
})
})
}
export const deleteItem = ({ commit, dispatch, state }, id) => {
return new Promise((resolve, reject) => {
window.axios.delete(`/api/items/${id}`).then((response) => {
commit(types.DELETE_ITEM, response.data)
resolve(response)
}).catch((err) => {
reject(err)
})
})
}
export const deleteMultipleItems = ({ commit, dispatch, state }, id) => {
return new Promise((resolve, reject) => {
window.axios.post(`/api/items/delete`, {'id': state.selectedItems}).then((response) => {
commit(types.DELETE_MULTIPLE_ITEMS, state.selectedItems)
resolve(response)
}).catch((err) => {
reject(err)
})
})
}
export const setSelectAllState = ({ commit, dispatch, state }, data) => {
commit(types.SET_SELECT_ALL_STATE, data)
}
export const selectAllItems = ({ commit, dispatch, state }) => {
if (state.selectedItems.length === state.items.length) {
commit(types.SET_SELECTED_ITEMS, [])
commit(types.SET_SELECT_ALL_STATE, false)
} else {
let allItemIds = state.items.map(item => item.id)
commit(types.SET_SELECTED_ITEMS, allItemIds)
commit(types.SET_SELECT_ALL_STATE, true)
}
}
export const selectItem = ({ commit, dispatch, state }, data) => {
commit(types.SET_SELECTED_ITEMS, data)
if (state.selectedItems.length === state.items.length) {
commit(types.SET_SELECT_ALL_STATE, true)
} else {
commit(types.SET_SELECT_ALL_STATE, false)
}
}

View File

@ -0,0 +1,4 @@
export const items = (state) => state.items
export const selectAllField = (state) => state.selectAllField
export const selectedItems = (state) => state.selectedItems
export const totalItems = (state) => state.totalItems

View File

@ -0,0 +1,22 @@
import mutations from './mutations'
import * as actions from './actions'
import * as getters from './getters'
const initialState = {
items: [],
totalItems: 0,
selectAllField: false,
selectedItems: []
}
export default {
namespaced: true,
state: initialState,
getters: getters,
actions: actions,
mutations: mutations
}

View File

@ -0,0 +1,8 @@
export const BOOTSTRAP_ITEMS = 'BOOTSTRAP_ITEMS'
export const ADD_ITEM = 'ADD_ITEM'
export const UPDATE_ITEM = 'UPDATE_ITEM'
export const DELETE_ITEM = 'DELETE_ITEM'
export const DELETE_MULTIPLE_ITEMS = 'DELETE_MULTIPLE_ITEMS'
export const SET_SELECTED_ITEMS = 'SET_SELECTED_ITEMS'
export const SET_TOTAL_ITEMS = 'SET_TOTAL_ITEMS'
export const SET_SELECT_ALL_STATE = 'SET_SELECT_ALL_STATE'

View File

@ -0,0 +1,44 @@
import * as types from './mutation-types'
export default {
[types.BOOTSTRAP_ITEMS] (state, items) {
state.items = items
},
[types.SET_TOTAL_ITEMS] (state, totalItems) {
state.totalItems = totalItems
},
[types.ADD_ITEM] (state, data) {
state.items.push(data.item)
},
[types.UPDATE_ITEM] (state, data) {
let pos = state.items.findIndex(item => item.id === data.item.id)
state.items[pos] = data.item
},
[types.DELETE_ITEM] (state, id) {
let index = state.items.findIndex(item => item.id === id)
state.items.splice(index, 1)
},
[types.DELETE_MULTIPLE_ITEMS] (state, selectedItems) {
selectedItems.forEach((item) => {
let index = state.items.findIndex(_item => _item.id === item.id)
state.items.splice(index, 1)
})
state.selectedItems = []
},
[types.SET_SELECTED_ITEMS] (state, data) {
state.selectedItems = data
},
[types.SET_SELECT_ALL_STATE] (state, data) {
state.selectAllField = data
}
}