|
| 1 | +import Progress from '../../../../src/component/Progress.mjs'; |
| 2 | +import Toolbar from '../../../../src/grid/footer/Toolbar.mjs'; |
| 3 | + |
| 4 | +/** |
| 5 | + * @class DevIndex.view.home.StatusToolbar |
| 6 | + * @extends Neo.grid.footer.Toolbar |
| 7 | + */ |
| 8 | +class StatusToolbar extends Toolbar { |
| 9 | + static config = { |
| 10 | + /** |
| 11 | + * @member {String} className='DevIndex.view.home.StatusToolbar' |
| 12 | + * @protected |
| 13 | + */ |
| 14 | + className: 'DevIndex.view.home.StatusToolbar', |
| 15 | + /** |
| 16 | + * @member {String} ntype='devindex-status-toolbar' |
| 17 | + * @protected |
| 18 | + */ |
| 19 | + ntype: 'devindex-status-toolbar', |
| 20 | + /** |
| 21 | + * @member {String[]} cls=['devindex-status-toolbar'] |
| 22 | + */ |
| 23 | + cls: ['devindex-status-toolbar'], |
| 24 | + /** |
| 25 | + * @member {Neo.data.Store|null} store_=null |
| 26 | + * @reactive |
| 27 | + */ |
| 28 | + store_: null, |
| 29 | + /** |
| 30 | + * @member {Object[]} items |
| 31 | + */ |
| 32 | + items: [{ |
| 33 | + module : Progress, |
| 34 | + flex : 1, |
| 35 | + max : 100, |
| 36 | + reference: 'progress', |
| 37 | + value : 0 |
| 38 | + }, { |
| 39 | + ntype: 'component', |
| 40 | + flex : 1 |
| 41 | + }, { |
| 42 | + ntype : 'label', |
| 43 | + reference: 'count-rows-label', |
| 44 | + style : {marginLeft: '10px'}, |
| 45 | + text : 'Visible: 0' |
| 46 | + }] |
| 47 | + } |
| 48 | + |
| 49 | + /** |
| 50 | + * Triggered before the store config gets changed. |
| 51 | + * @param {Neo.data.Store|Object|null} value |
| 52 | + * @param {Neo.data.Store|null} oldValue |
| 53 | + * @returns {Neo.data.Store} |
| 54 | + * @protected |
| 55 | + */ |
| 56 | + beforeSetStore(value, oldValue) { |
| 57 | + let me = this, |
| 58 | + listeners = { |
| 59 | + filter : me.updateRowsLabel, |
| 60 | + load : me.onStoreLoad, |
| 61 | + progress: me.onStoreProgress, |
| 62 | + scope : me |
| 63 | + }; |
| 64 | + |
| 65 | + oldValue?.un(listeners); |
| 66 | + |
| 67 | + // Store might be passed as an instance or config |
| 68 | + if (value && value.on) { |
| 69 | + value.on(listeners); |
| 70 | + } |
| 71 | + |
| 72 | + return value |
| 73 | + } |
| 74 | + |
| 75 | + /** |
| 76 | + * @param {Object} data |
| 77 | + */ |
| 78 | + onStoreLoad(data) { |
| 79 | + this.updateRowsLabel(); |
| 80 | + |
| 81 | + let progress = this.getItem('progress'); |
| 82 | + |
| 83 | + if (progress) { |
| 84 | + progress.value = progress.max; |
| 85 | + |
| 86 | + this.timeout(500).then(() => { |
| 87 | + progress.hidden = true |
| 88 | + }) |
| 89 | + } |
| 90 | + } |
| 91 | + |
| 92 | + /** |
| 93 | + * @param {Object} data {loaded, total} |
| 94 | + */ |
| 95 | + onStoreProgress(data) { |
| 96 | + let progress = this.getItem('progress'); |
| 97 | + |
| 98 | + if (progress) { |
| 99 | + progress.hidden = false; |
| 100 | + progress.max = data.total || 100; |
| 101 | + progress.value = data.loaded; |
| 102 | + |
| 103 | + // Indeterminate state if total is unknown |
| 104 | + if (!data.total) { |
| 105 | + progress.value = null |
| 106 | + } |
| 107 | + } |
| 108 | + } |
| 109 | + |
| 110 | + /** |
| 111 | + * |
| 112 | + */ |
| 113 | + updateRowsLabel() { |
| 114 | + let {store} = this; |
| 115 | + |
| 116 | + if (store) { |
| 117 | + this.getItem('count-rows-label').text = 'Visible: ' + store.count |
| 118 | + } |
| 119 | + } |
| 120 | +} |
| 121 | + |
| 122 | +export default Neo.setupClass(StatusToolbar); |
0 commit comments