adminview-cache.js
5.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
/*
*
* ADOBE CONFIDENTIAL
* __________________
*
* Copyright 2014 Adobe Systems Incorporated
* All Rights Reserved.
*
* NOTICE: All information contained herein is, and remains
* the property of Adobe Systems Incorporated and its suppliers,
* if any. The intellectual and technical concepts contained
* herein are proprietary to Adobe Systems Incorporated and its
* suppliers and are protected by trade secret or copyright law.
* Dissemination of this information or reproduction of this material
* is strictly forbidden unless prior written permission is obtained
* from Adobe Systems Incorporated.
*/
define('screens/player/ui/adminview-cache', [
'underscore',
'jquery',
'screens/player/shared/util',
'./baseview',
'screens/player/shared/serviceadmin',
'screens/player/firmware/storage/storage',
'screens/player/firmware/cache/cache',
'screens/player/store/store'
], function(_, $, Util, BaseView, ServiceAdmin, Storage, Cache, Store) {
'use strict';
var DEFAULT_OPTIONS = {
};
function _toggleClearCacheButtons(cache) {
$('.cache-clear').attr('disabled', !!cache.clearing);
}
var CacheAdminView = BaseView.extend(/** @lends CacheAdminView.prototype */{
template: function(state) {
function fu(size) {
return Util.formatUnit(size, Util.UNITS_DI_IEC, 1);
}
var usageStr = 'n/a';
if (state) {
var usage = Util.get(state, 'status.usage');
}
if (usage && usage.used) {
// Usage:
// %d free on storage %s
// %d of %d used.
usageStr = fu(usage.free) + ' free on storage \'' + usage.volume + '\'<br>';
usageStr += fu(usage.used) + ' of ' + fu(usage.total) + ' used';
}
var html = '<h1>Content Cache</h1>';
html += '<h2>Usage</h2>';
html += '<h3 class="aem-ScreensPlayer-channelsUsage">' + usageStr + '</h3>';
html += '<h2>Clear Cache</h2>';
html += '<h3>';
html += '<button class="cache-clear" id="cache-clear-channels">Channels</button>';
html += '<button class="cache-clear" id="cache-clear-app">Application</button>';
html += '</h3>';
html += '<h3><button class="cache-clear" id="cache-clear-all">All</button></h3>';
return html;
},
className: 'aem-ScreensPlayer-admin-view',
events: {
'click #cache-clear-channels': 'clearChannelsData',
'click #cache-clear-app': 'clearAppCache',
'click #cache-clear-all': 'clearAll'
},
/**
* @classdesc View that renders the admin menu
* @class AdminView
* @extends BaseView
*
* @param {Object} [options] An object of configurable options.
*/
constructor: function(options) {
this._initOptions(options, DEFAULT_OPTIONS);
CacheAdminView.__super__.constructor.apply(this, arguments);
this.$el.on('show', this.onShow.bind(this));
this.$el.on('hide', this.onHide.bind(this));
},
/**
* Event handler for when this view's contents are hidden
*/
onHide: function() {
var store = ServiceAdmin.getService(Store.serviceName);
if (this._storageChangeListener) {
store.unsubscribe(this._storageChangeListener);
this._storageChangeListener = null;
}
if (this._cacheChangeListener) {
store.unsubscribe(this._cacheChangeListener);
this._cacheChangeListener = null;
}
},
/**
* Event handler for when this view's contents are shown
*/
onShow: function() {
var store = ServiceAdmin.getService(Store.serviceName);
if (this._storageChangeListener) {
store.unsubscribe(this._storageChangeListener);
}
if (this._cacheChangeListener) {
store.unsubscribe(this._cacheChangeListener);
}
this._storageChangeListener = store.subscribe(this.render.bind(this), Storage.NAMESPACE);
this._cacheChangeListener = store.subscribe(_toggleClearCacheButtons, Cache.NAMESPACE);
var state = store.getState();
this.render(state[Storage.NAMESPACE]);
_toggleClearCacheButtons(state[Cache.NAMESPACE]);
},
render: function(state) {
this.$el.html(this.template(state));
return this;
},
clearChannelsData: function() {
var flags = {};
flags[Cache.FLAGS.REBOOT_ON_COMPLETE] = true;
var cacheSvc = ServiceAdmin.getService(Cache.serviceName);
cacheSvc.clearChannelsData(flags);
},
clearAppCache: function() {
var flags = {};
flags[Cache.FLAGS.REBOOT_ON_COMPLETE] = true;
var cacheSvc = ServiceAdmin.getService(Cache.serviceName);
cacheSvc.clearAppCache(flags);
},
clearAll: function() {
var flags = {};
flags[Cache.FLAGS.REBOOT_ON_COMPLETE] = true;
var cacheSvc = ServiceAdmin.getService(Cache.serviceName);
cacheSvc.clearAll(flags);
}
});
// return module exports
return CacheAdminView;
});