Skip to content

Commit b78b512

Browse files
committed
Refactored What's New into separate directory/class
1 parent 683b9c1 commit b78b512

File tree

6 files changed

+153
-55
lines changed

6 files changed

+153
-55
lines changed

src/ui/builder.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ goog.require('cwc.ui.Sidebar');
6161
goog.require('cwc.ui.StatusBar');
6262
goog.require('cwc.ui.Tour');
6363
goog.require('cwc.ui.Tutorial');
64+
goog.require('cwc.ui.WhatsNew');
6465
goog.require('cwc.ui.connectScreen.Screens');
6566
goog.require('cwc.ui.gapi.Handler');
6667
goog.require('cwc.utils.Dialog');
@@ -111,6 +112,7 @@ cwc.ui.BuilderHelpers = {
111112
'statusBar': cwc.ui.StatusBar,
112113
'tour': cwc.ui.Tour,
113114
'tutorial': cwc.ui.Tutorial,
115+
'whatsNew': cwc.ui.WhatsNew,
114116
};
115117

116118

src/ui/help/help.js

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -94,26 +94,10 @@ cwc.ui.Help.prototype.showChangelog = function() {
9494
noticeWebview.addEventListener('contentload', function() {
9595
noticeWebview['insertCSS']({'code': 'html {overflow-y: scroll;}'});
9696
});
97-
this.initWhatsNewControl_();
97+
this.helper.getInstance('whatsNew').init(goog.dom.getElement(this.prefix +
98+
'whats_new-checkbox'));
9899
};
99100

100-
101-
cwc.ui.Help.prototype.initWhatsNewControl_ = function() {
102-
let showWhatsNew = goog.dom.getElement(this.prefix + 'whats_new-checkbox');
103-
let userConfigInstance = this.helper.getInstance('userConfig');
104-
if (userConfigInstance.get(cwc.userConfigType.GENERAL,
105-
cwc.userConfigName.SKIP_WHATS_NEW)) {
106-
showWhatsNew.parentNode['MaterialCheckbox']['uncheck']();
107-
} else {
108-
showWhatsNew.parentNode['MaterialCheckbox']['check']();
109-
}
110-
this.events_.listen(showWhatsNew, goog.events.EventType.CHANGE, () => {
111-
userConfigInstance.set(cwc.userConfigType.GENERAL,
112-
cwc.userConfigName.SKIP_WHATS_NEW, !showWhatsNew.checked);
113-
});
114-
};
115-
116-
117101
cwc.ui.Help.prototype.showHelp = function() {
118102
let dialogInstance = this.helper.getInstance('dialog');
119103
dialogInstance.showTemplate('Help', cwc.soy.Help.help,

src/ui/help/help.soy

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,15 @@
137137
src="../CHANGELOG.html" style="width: 600px; height: 500px;"></iframe>
138138
{/if}
139139

140+
{call .whatsNew data="all"/}
141+
{/template}
142+
143+
/**
144+
* Enable/Disable showing What's New checkbox
145+
*/
146+
{template .whatsNew}
147+
{@param prefix: string}
148+
140149
<label id="{$prefix}whats_new-show" for="{$prefix}whats_new-checkbox" class="mdl-checkbox mdl-js-checkbox mdl-js-ripple-effect">
141150
<input type="checkbox" id="{$prefix}whats_new-checkbox" class="mdl-checkbox__input"/>
142151
<div class="mdl-checkbox__label">

src/ui/select_screen/select_screen.js

Lines changed: 1 addition & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,7 @@ cwc.ui.SelectScreen.prototype.showTemplate_ = function(template) {
296296
// Event Handling
297297
this.eventTarget_.dispatchEvent(
298298
cwc.ui.SelectScreen.Events.changeView(this.nodeContent));
299-
this.showWhatsNew_();
299+
this.helper.getInstance('whatsNew').show();
300300
} else {
301301
console.error('Unable to render template', template);
302302
}
@@ -366,40 +366,4 @@ cwc.ui.SelectScreen.prototype.handleFileClick_ = function(e) {
366366
}
367367
}
368368
};
369-
370-
/**
371-
* @private
372-
*/
373-
cwc.ui.SelectScreen.prototype.showWhatsNew_ = function() {
374-
let version = this.helper.getAppVersion();
375-
376-
let userConfigInstance = this.helper.getInstance('userConfig');
377-
if (!userConfigInstance) {
378-
console.error('Failed to get user config instance');
379-
return;
380-
}
381-
382-
if (userConfigInstance.get(cwc.userConfigType.GENERAL,
383-
cwc.userConfigName.SKIP_WHATS_NEW)) {
384-
return;
385-
}
386-
387-
if (userConfigInstance.get(cwc.userConfigType.GENERAL,
388-
cwc.userConfigName.LAST_WHATS_NEW_VERSION) == version) {
389-
return;
390-
}
391-
392-
let helpInstance = this.helper.getInstance('help');
393-
if (!helpInstance) {
394-
console.error('Failed to help instance');
395-
return;
396-
}
397-
398-
// Flag that we've show What's New for this version
399-
if (userConfigInstance) {
400-
userConfigInstance.set(cwc.userConfigType.GENERAL,
401-
cwc.userConfigName.LAST_WHATS_NEW_VERSION, version);
402-
}
403-
helpInstance.showChangelog(true);
404-
};
405369
});

src/ui/whats_new/whats_new.js

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
/**
2+
* @fileoverview Select screen for the different coding modes and formats.
3+
*
4+
* @license Copyright 2019 The Coding with Chrome Authors.
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*
18+
* @author [email protected] (Adam Carheden)
19+
*/
20+
goog.provide('cwc.ui.WhatsNew');
21+
22+
goog.require('cwc.utils.Events');
23+
goog.require('cwc.utils.Helper');
24+
25+
goog.require('goog.dom');
26+
27+
28+
goog.scope(function() {
29+
/**
30+
* @param {!cwc.utils.Helper} helper
31+
* @constructor
32+
* @struct
33+
*/
34+
cwc.ui.WhatsNew = function(helper) {
35+
/** @type {!cwc.utils.Helper} */
36+
this.helper = helper;
37+
38+
/** @type {string} */
39+
this.prefix = this.helper.getPrefix('whats_new');
40+
41+
/** @private {!cwc.utils.Events} */
42+
this.events_ = new cwc.utils.Events(this.name, this.prefix, this);
43+
};
44+
45+
/**
46+
* Conditionally shows the changelog if it hasn't been shown for this version
47+
* yet and if the user hasn't disabling showing it for new versions.
48+
*/
49+
cwc.ui.WhatsNew.prototype.show = function() {
50+
let version = this.helper.getAppVersion();
51+
52+
let userConfigInstance = this.helper.getInstance('userConfig');
53+
if (!userConfigInstance) {
54+
console.error('Failed to get user config instance');
55+
return;
56+
}
57+
58+
if (userConfigInstance.get(cwc.userConfigType.GENERAL,
59+
cwc.userConfigName.SKIP_WHATS_NEW)) {
60+
return;
61+
}
62+
63+
if (userConfigInstance.get(cwc.userConfigType.GENERAL,
64+
cwc.userConfigName.LAST_WHATS_NEW_VERSION) == version) {
65+
return;
66+
}
67+
68+
let helpInstance = this.helper.getInstance('help');
69+
if (!helpInstance) {
70+
console.error('Failed to help instance');
71+
return;
72+
}
73+
74+
// Flag that we've show What's New for this version
75+
if (userConfigInstance) {
76+
userConfigInstance.set(cwc.userConfigType.GENERAL,
77+
cwc.userConfigName.LAST_WHATS_NEW_VERSION, version);
78+
}
79+
helpInstance.showChangelog(true);
80+
};
81+
82+
/**
83+
* Synchronizes UI component with underlying user config
84+
* @param {!Element} checkbox
85+
*/
86+
cwc.ui.WhatsNew.prototype.init = function(checkbox) {
87+
if (!checkbox) {
88+
return;
89+
}
90+
91+
this.events_.clear();
92+
93+
let userConfigInstance = this.helper.getInstance('userConfig');
94+
if (userConfigInstance.get(cwc.userConfigType.GENERAL,
95+
cwc.userConfigName.SKIP_WHATS_NEW)) {
96+
checkbox.parentNode['MaterialCheckbox']['uncheck']();
97+
} else {
98+
checkbox.parentNode['MaterialCheckbox']['check']();
99+
}
100+
this.events_.listen(checkbox, goog.events.EventType.CHANGE, () => {
101+
userConfigInstance.set(cwc.userConfigType.GENERAL,
102+
cwc.userConfigName.SKIP_WHATS_NEW, !checkbox.checked);
103+
});
104+
};
105+
});

src/ui/whats_new/whats_new.soy

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/**
2+
* @fileoverview Help for Coding in Chrome editor.
3+
*
4+
* @license Copyright 2019 The Coding with Chrome Authors.
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*
18+
* @author [email protected] (Adam Carheden)
19+
*/
20+
{namespace cwc.soy.WhatsNew autoescape="strict"}
21+
22+
/**
23+
* Enable/Disable showing What's New checkbox
24+
*/
25+
{template .enable}
26+
{@param prefix: string}
27+
28+
<label id="{$prefix}whats_new-show" for="{$prefix}whats_new-checkbox" class="mdl-checkbox mdl-js-checkbox mdl-js-ripple-effect">
29+
<input type="checkbox" id="{$prefix}whats_new-checkbox" class="mdl-checkbox__input"/>
30+
<div class="mdl-checkbox__label">
31+
{msg desc="Checkbox to enable/disable showing a notification when a new release is installed."}@@SELECT_SCREEN__ENABLE_WHATS_NEW{/msg}
32+
</div>
33+
</label>
34+
{/template}

0 commit comments

Comments
 (0)