UNPKG

corporate-frontend-mithril

Version:

Corporate frontend MithrilJS modules

49 lines (35 loc) 1.25 kB
const DataService = require('./data-service'); const ArtsConstant = require('../constant/arts-constant'); module.exports = function() { let _selectOptSet = {}; let _unitDetails = undefined; let vm = { get unitList() { let list = DataService.resultStream(); return Object.is(typeof list, 'object') ? list.map( obj => Object.assign({}, obj, {name: `${obj.UOS_alpha}${obj.UOS_digit} ${obj.UOS_name}`}) ) : undefined; }, get unitDetails() { return _unitDetails; }, get isLoading() { return Object.is(DataService.resultStream(), ArtsConstant.LOADING_RESULT); }, get noResults() { return Object.is(DataService.resultStream(), ArtsConstant.NO_RESULT) ? true : false; }, }; //------------------- View Handlers --------------------- vm.selectedOpt = function({key, obj}) { _selectOptSet[key] = obj ? obj.value : undefined; }; vm.fetchUnitList = function() { _unitDetails = undefined; DataService.fetchUnitList({obj:_selectOptSet}); }, vm.showUnitDetails = function({obj}) { _unitDetails = obj; }; return vm; };