Skip to content

Commit

Permalink
Bookmark support.
Browse files Browse the repository at this point in the history
  • Loading branch information
mikeburg committed Sep 30, 2024
1 parent 33857e8 commit c4b550d
Show file tree
Hide file tree
Showing 8 changed files with 143 additions and 2 deletions.
72 changes: 72 additions & 0 deletions app/controllers/bookmark.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
import ClubhouseController from "clubhouse/controllers/clubhouse-controller";
import {tracked} from '@glimmer/tracking';
import {action} from '@ember/object';

export default class BookmarkController extends ClubhouseController {
@tracked isLoading = false;
@tracked haveError = null;
@tracked notFound = false;
@tracked content = null;
@tracked updatedAt;

@tracked countdown;

@tracked now;

refreshTime = 0;

async loadDocument() {
this.isLoading = true;
this.haveError = null;
try {
const {content, updated_at, refresh_time} = await this.ajax.request(`bookmark/${this.bookmarkId}`);
this.content = content;
this.updatedAt = updated_at;
this.refreshTime = refresh_time * 60;
this.countdown = refresh_time * 60;
} catch (e) {
this.haveError = e.message;
if (e.status !== 404) {
this.refreshTime = 1;
}
} finally {
this.isLoading = false;
}
}

setupTick() {
this.timeoutId = setInterval(() => this.tick(), 1000);
}

cancelTick() {
if (this.timeoutId) {
clearTimeout(this.timeoutId);
this.timeoutId = null;
}
}

tick() {
this.now = new Date();
if (this.refreshTime > 0) {
this.refreshTime--;
this.countdown = this.refreshTime;
if (!this.refreshTime) {
this.loadDocument();
}
}
}

@action
formatTimeLeft() {
const duration = this.countdown;
let minutes = Math.floor(duration / 60);
let seconds = Math.floor(duration % 60);

if (minutes) {
minutes = Math.floor((duration + 59) / 60);
return `${minutes} minute${minutes !== 1 ? 's' :''}`;
} else {
return `${seconds} second${seconds !== 1 ? 's' :''}`;
}
}
}
1 change: 1 addition & 0 deletions app/models/document.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,5 @@ export default class DocumentModel extends Model {
@attr('', {readOnly: true}) person_create;
@attr('number', {readOnly: true}) person_update_id;
@attr('', {readOnly: true}) person_update;
@attr('number') refresh_time;
}
1 change: 1 addition & 0 deletions app/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ Router.map(function () {
this.route('reset-password');
this.route('register');
// this.route('sso'); -- uncomment if will SSO is ever implemented
this.route('bookmark', { path: '/bookmark/:bookmark_id'});

this.route('me', function () {
this.route('homepage', {path: '/'});
Expand Down
27 changes: 27 additions & 0 deletions app/routes/bookmark.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import ClubhouseRoute from "clubhouse/routes/clubhouse-route";

export default class BookmarkRoute extends ClubhouseRoute {
authRequired = false;

model({bookmark_id}) {
return bookmark_id;
}

setupController(controller, bookmarkId) {
controller.content = null;
controller.bookmarkId = bookmarkId;
controller.refreshTime = 0;
controller.countdown = 0;
controller.notFound = false;
controller.setupTick();
controller.loadDocument();
this.session.showingBookmark = true;
}

resetController(controller, isExiting) {
if (isExiting) {
controller.cancelTick();
this.session.showingBookmark = false;
}
}
}
1 change: 1 addition & 0 deletions app/services/session.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ export default class extends SessionService {
@tracked showOfflineDialog = false;

@tracked isOffline = false;
@tracked showingBookmark = false;

constructor() {
super(...arguments);
Expand Down
4 changes: 4 additions & 0 deletions app/templates/admin/documents.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@
@label="Document Tag -- DO NOT CHANGE!!!"
@size={{30}}
@maxlength={{80}}/>
<f.number @name="refresh_time"
@label="Refresh minutes (bookmarks only):"
@size={{5}}
/>
</FormRow>
<FormRow>
<f.text @name="description"
Expand Down
4 changes: 2 additions & 2 deletions app/templates/application.hbs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<ToastRegistry/>
<ModalRegistry/>
{{#unless this.session.isOffline}}
{{#unless (or this.session.isOffline this.session.showingBookmark)}}
<header class="d-print-none">
<Navbar/>
{{#if (has-role "admin" "manage" "vc" "mentor")}}
Expand All @@ -23,7 +23,7 @@

<div id="body-row" {{on-insert this.bodyRowInserted}}>{{outlet}}</div>

{{#unless this.session.isOffline}}
{{#unless (or this.session.isOffline this.session.showingBookmark)}}
<footer class="d-print-none">
&copy; 2008-{{dayjs-format "" "YYYY"}} Black Rock City, LLC.
<span class="d-inline-block">
Expand Down
35 changes: 35 additions & 0 deletions app/templates/bookmark.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<main>
<div class="d-flex flex-column flex-md-row justify-content-between text-muted text-small px-2">
<div>
{{#unless this.notFound}}
{{#if this.isLoading}}
<SpinIcon/>
Refreshing page
{{else if this.refreshTime}}
Page refresh in
{{this.formatTimeLeft}}
{{/if}}
{{/unless}}
</div>
{{#if this.content}}
<div>
Document updated {{dayjs-format this.updatedAt "dddd, MMM DD @ HH:mm"}}
</div>
{{/if}}
<div>
Current time {{dayjs-format this.now "ddd, MMM DD @ HH:mm"}}
</div>
</div>
<div class="p-2 mt-3">
{{#if this.notFound}}
<div class="fs-3 fw-bold">
Bookmark document was not found.
</div>
{{else if this.content}}
{{!template-lint-disable no-triple-curlies}}
{{{this.content}}}
{{else if this.isLoading}}
<LoadingDialog/>
{{/if}}
</div>
</main>

0 comments on commit c4b550d

Please sign in to comment.