History

Sanity-check decaffeinate app.views.Notif

Simon Legner committed 2 years ago

Commit 1efb7941 parent 9073fa25 files · +37 −96Browse files

Showing the changes to assets/javascripts/views (5 of 5 files). Show all

Unified · Split

5 files
  1. assets/javascripts/views/misc/news.js +12 −27
  2. assets/javascripts/views/misc/notice.js +2 −12
  3. assets/javascripts/views/misc/notif.js +9 −18
  4. assets/javascripts/views/misc/tip.js +2 −12
  5. assets/javascripts/views/misc/updates.js +12 −27
assets/javascripts/views/misc/news.js+12−27
@@ -1,23 +1,11 @@
1// TODO: This file was created by bulk-decaffeinate.
2// Sanity-check the conversion and remove this comment.
3/*
4 * decaffeinate suggestions:
5 * DS101: Remove unnecessary use of Array.from
6 * DS102: Remove unnecessary code created because of implicit returns
7 * DS205: Consider reworking code to avoid use of IIFEs
8 * DS206: Consider reworking classes to avoid initClass
9 * Full docs: https://github.com/decaffeinate/decaffeinate/blob/main/docs/suggestions.md
10 */
11//= require views/misc/notif1//= require views/misc/notif
12 2
13app.views.News = class News extends app.views.Notif {3app.views.News = class News extends app.views.Notif {
14 static initClass() {4 static className = "_notif _notif-news";
15 this.className += " _notif-news";
16 5
17 this.defautOptions = { autoHide: 30000 };6 static defaultOptions = { autoHide: 30000 };
18 }
19 7
20 init() {8 init0() {
21 this.unreadNews = this.getUnreadNews();9 this.unreadNews = this.getUnreadNews();
22 if (this.unreadNews.length) {10 if (this.unreadNews.length) {
23 this.show();11 this.show();
@@ -30,21 +18,19 @@ app.views.News = class News extends app.views.Notif { · 6 unmodified lines
30 }18 }
31 19
32 getUnreadNews() {20 getUnreadNews() {
33 let time;21 let time = this.getLastReadTime();
34 if (!(time = this.getLastReadTime())) {22 if (!time) {
35 return [];23 return [];
36 }24 }
37 25
38 return (() => {26 const result = [];
39 const result = [];27 for (var news of app.news) {
40 for (var news of Array.from(app.news)) {28 if (new Date(news[0]).getTime() <= time) {
41 if (new Date(news[0]).getTime() <= time) {29 break;
42 break;
43 }
44 result.push(news);
45 }30 }
46 return result;31 result.push(news);
47 })();32 }
33 return result;
48 }34 }
49 35
50 getLastNewsTime() {36 getLastNewsTime() {
@@ -59,4 +45,3 @@ app.views.News = class News extends app.views.Notif { · 8 unmodified lines
59 app.settings.set("news", this.getLastNewsTime());45 app.settings.set("news", this.getLastNewsTime());
60 }46 }
61};47};
62app.views.News.initClass();
assets/javascripts/views/misc/notice.js+2−12
@@ -1,15 +1,6 @@
1// TODO: This file was created by bulk-decaffeinate.
2// Sanity-check the conversion and remove this comment.
3/*
4 * decaffeinate suggestions:
5 * DS206: Consider reworking classes to avoid initClass
6 * Full docs: https://github.com/decaffeinate/decaffeinate/blob/main/docs/suggestions.md
7 */
8app.views.Notice = class Notice extends app.View {1app.views.Notice = class Notice extends app.View {
9 static initClass() {2 static className = "_notice";
10 this.className = "_notice";3 static attributes = { role: "alert" };
11 this.attributes = { role: "alert" };
12 }
13 4
14 constructor(type, ...args) {5 constructor(type, ...args) {
15 super();6 super();
@@ -44,4 +35,3 @@ app.views.Notice = class Notice extends app.View { · 28 unmodified lines
44 $.remove(this.el);35 $.remove(this.el);
45 }36 }
46};37};
47app.views.Notice.initClass();
assets/javascripts/views/misc/notif.js+9−18
@@ -1,29 +1,21 @@
1// TODO: This file was created by bulk-decaffeinate.
2// Sanity-check the conversion and remove this comment.
3/*
4 * decaffeinate suggestions:
5 * DS206: Consider reworking classes to avoid initClass
6 * DS207: Consider shorter variations of null checks
7 * Full docs: https://github.com/decaffeinate/decaffeinate/blob/main/docs/suggestions.md
8 */
9app.views.Notif = class Notif extends app.View {1app.views.Notif = class Notif extends app.View {
10 static initClass() {2 static className = "_notif";
11 this.className = "_notif";3 static activeClass = "_in";
12 this.activeClass = "_in";4 static attributes = { role: "alert" };
13 this.attributes = { role: "alert" };
14 5
15 this.defaultOptions = { autoHide: 15000 };6 static defaultOptions = { autoHide: 15000 };
16 7
17 this.events = { click: "onClick" };8 static events = { click: "onClick" };
18 }
19 9
20 constructor(type, options) {10 constructor(type, options) {
21 super();11 super();
22 this.type = type;12 this.type = type;
23 this.options = $.extend({}, this.constructor.defaultOptions, options || {});13 this.options = $.extend({}, this.constructor.defaultOptions, options || {});
14 this.init0(); // needs this.options
15 this.refreshElements();
24 }16 }
25 17
26 init() {18 init0() {
27 this.show();19 this.show();
28 }20 }
29 21
@@ -55,7 +47,7 @@ app.views.Notif = class Notif extends app.View { · 25 unmodified lines
55 }47 }
56 48
57 position() {49 position() {
58 const notifications = $$(`.${app.views.Notif.className}`);50 const notifications = $$(`.${Notif.className}`);
59 if (notifications.length) {51 if (notifications.length) {
60 const lastNotif = notifications[notifications.length - 1];52 const lastNotif = notifications[notifications.length - 1];
61 this.el.style.top =53 this.el.style.top =
@@ -77,4 +69,3 @@ app.views.Notif = class Notif extends app.View { · 15 unmodified lines
77 }69 }
78 }70 }
79};71};
80app.views.Notif.initClass();
assets/javascripts/views/misc/tip.js+2−12
@@ -1,21 +1,11 @@
1// TODO: This file was created by bulk-decaffeinate.
2// Sanity-check the conversion and remove this comment.
3/*
4 * decaffeinate suggestions:
5 * DS206: Consider reworking classes to avoid initClass
6 * Full docs: https://github.com/decaffeinate/decaffeinate/blob/main/docs/suggestions.md
7 */
8//= require views/misc/notif1//= require views/misc/notif
9 2
10app.views.Tip = class Tip extends app.views.Notif {3app.views.Tip = class Tip extends app.views.Notif {
11 static initClass() {4 static className = "_notif _notif-tip";
12 this.className = "_notif _notif-tip";
13 5
14 this.defautOptions = { autoHide: false };6 static defautOptions = { autoHide: false };
15 }
16 7
17 render() {8 render() {
18 this.html(this.tmpl(`tip${this.type}`));9 this.html(this.tmpl(`tip${this.type}`));
19 }10 }
20};11};
21app.views.Tip.initClass();
assets/javascripts/views/misc/updates.js+12−27
@@ -1,23 +1,11 @@
1// TODO: This file was created by bulk-decaffeinate.
2// Sanity-check the conversion and remove this comment.
3/*
4 * decaffeinate suggestions:
5 * DS101: Remove unnecessary use of Array.from
6 * DS102: Remove unnecessary code created because of implicit returns
7 * DS205: Consider reworking code to avoid use of IIFEs
8 * DS206: Consider reworking classes to avoid initClass
9 * Full docs: https://github.com/decaffeinate/decaffeinate/blob/main/docs/suggestions.md
10 */
11//= require views/misc/notif1//= require views/misc/notif
12 2
13app.views.Updates = class Updates extends app.views.Notif {3app.views.Updates = class Updates extends app.views.Notif {
14 static initClass() {4 static className = "_notif _notif-news";
15 this.className += " _notif-news";
16 5
17 this.defautOptions = { autoHide: 30000 };6 static defautOptions = { autoHide: 30000 };
18 }
19 7
20 init() {8 init0() {
21 this.lastUpdateTime = this.getLastUpdateTime();9 this.lastUpdateTime = this.getLastUpdateTime();
22 this.updatedDocs = this.getUpdatedDocs();10 this.updatedDocs = this.getUpdatedDocs();
23 this.updatedDisabledDocs = this.getUpdatedDisabledDocs();11 this.updatedDisabledDocs = this.getUpdatedDisabledDocs();
@@ -46,18 +34,16 @@ app.views.Updates = class Updates extends app.views.Notif { · 22 unmodified lines
46 if (!this.lastUpdateTime) {34 if (!this.lastUpdateTime) {
47 return [];35 return [];
48 }36 }
49 return (() => {37 const result = [];
50 const result = [];38 for (var doc of Array.from(app.disabledDocs.all())) {
51 for (var doc of Array.from(app.disabledDocs.all())) {39 if (
52 if (40 doc.mtime > this.lastUpdateTime &&
53 doc.mtime > this.lastUpdateTime &&41 app.docs.findBy("slug_without_version", doc.slug_without_version)
54 app.docs.findBy("slug_without_version", doc.slug_without_version)42 ) {
55 ) {43 result.push(doc);
56 result.push(doc);
57 }
58 }44 }
59 return result;45 }
60 })();46 return result;
61 }47 }
62 48
63 getLastUpdateTime() {49 getLastUpdateTime() {
@@ -73,4 +59,3 @@ app.views.Updates = class Updates extends app.views.Notif { · 9 unmodified lines
73 );59 );
74 }60 }
75};61};
76app.views.Updates.initClass();