Last active
August 20, 2022 06:21
-
-
Save denzo/8f4ed11f7559390f9360457b5206cf56 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// app/models/action.js | |
import Model from 'ember-data/model'; | |
import attr from 'ember-data/attr'; | |
export default Model.extend({ | |
label: attr('string'), | |
status: attr('action-status') // before it was attr('number') | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// app/transforms/action-status.js | |
import Transform from 'ember-data/transform'; | |
import { STATUSES } from '../constants/actions'; | |
export default Transform.extend({ | |
deserialize(serialized) { | |
return STATUSES.findBy('value', serialized); | |
}, | |
serialize(deserialized = {}) { | |
return deserialized.value; | |
} | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// app/constants/actions.js | |
const STATUS_TO_DO = { value: 0 }; | |
const STATUS_IN_PROGRESS = { value: 10 }; | |
const STATUS_DONE = { value: 50 }; | |
const STATUS_CANT_DO = { value: 60 }; | |
const STATUS_OVERDUE = { value: -1 }; | |
const STATUSES = [STATUS_TO_DO, STATUS_IN_PROGRESS, STATUS_DONE, STATUS_CANT_DO]; | |
export { | |
STATUS_TO_DO, STATUS_IN_PROGRESS, STATUS_DONE, STATUS_CANT_DO, STATUS_OVERDUE, STATUSES | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// app/constants/actions.js | |
const STATUS_TO_DO = { value: 0, label: 'To Do' }; | |
const STATUS_IN_PROGRESS = { value: 10, label: 'In Progress' }; | |
const STATUS_DONE = { value: 50, label: 'Done' }; | |
const STATUS_CANT_DO = { value: 60, label: 'Can\'t Do' }; | |
const STATUS_OVERDUE = { value: -1, label: 'Overdue' }; | |
... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// app/componets/action-details/component.js | |
setStatus(newStatus) { | |
const model = get(this, 'model'); | |
if ([0, 10].includes(get(model, 'status')) && [50, 60].includes(newStatus)) { | |
set(model, 'completedAt', new Date()); | |
} | |
set(model, 'status', newStatus); | |
model.save(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment