From 6e672f826275649b395833e66eed41a71a928bb4 Mon Sep 17 00:00:00 2001 From: rob Date: Sun, 31 Jul 2022 15:25:01 -0400 Subject: [PATCH] scooted room views into chat/room --- app/controllers/chat.js | 35 ++++++++++++++++--- app/views/chat/index.pug | 11 ++++-- app/views/chat/layouts/room.pug | 13 ++++--- app/views/chat/room-editor.pug | 54 ----------------------------- app/views/chat/room/editor.pug | 55 ++++++++++++++++++++++++++++++ app/views/chat/{ => room}/view.pug | 6 ++-- 6 files changed, 107 insertions(+), 67 deletions(-) delete mode 100644 app/views/chat/room-editor.pug create mode 100644 app/views/chat/room/editor.pug rename app/views/chat/{ => room}/view.pug (93%) diff --git a/app/controllers/chat.js b/app/controllers/chat.js index 2cef875..ae22834 100644 --- a/app/controllers/chat.js +++ b/app/controllers/chat.js @@ -37,23 +37,34 @@ class ChatController extends SiteController { router.param('roomId', this.populateRoomId.bind(this)); router.post( - '/:roomId', + '/room/:roomId', limiterService.create(limiterService.config.chat.postRoomUpdate), this.postRoomUpdate.bind(this), ); router.post( - '/', + '/room', limiterService.create(limiterService.config.chat.postRoomCreate), this.postRoomCreate.bind(this), ); router.get( - '/:roomId', + '/room/create', + this.getRoomEditor.bind(this), + ); + + router.get( + '/room/:roomId', limiterService.create(limiterService.config.chat.getRoomView), this.getRoomView.bind(this), ); + router.get( + '/room', + limiterService.create(limiterService.config.chat.getRoomView), + this.getRoomHome.bind(this), + ); + router.get( '/', limiterService.create(limiterService.config.chat.getHome), @@ -99,6 +110,10 @@ class ChatController extends SiteController { } } + async getRoomEditor (req, res) { + res.render('chat/room/editor'); + } + async getRoomView (req, res, next) { const { chat: chatService } = this.dtp.services; try { @@ -107,13 +122,25 @@ class ChatController extends SiteController { const pagination = { skip: 0, cpp: 20 }; res.locals.chatMessages = await chatService.getChannelHistory(res.locals.room, pagination); - res.render('chat/view'); + res.render('chat/room/view'); } catch (error) { this.log.error('failed to render chat room view', { roomId: req.params.roomId, error }); return next(error); } } + async getRoomHome (req, res, next) { + const { chat: chatService } = this.dtp.services; + try { + res.locals.pagination = this.getPaginationParameters(req, 20); + res.locals.rooms = await chatService.getPublicRooms(req.user, res.locals.pagination); + res.render('chat/room/index'); + } catch (error) { + this.log.error('failed to render room home', { error }); + return next(error); + } + } + async getHome (req, res) { res.locals.pageTitle = 'Chat Home'; res.render('chat/index'); diff --git a/app/views/chat/index.pug b/app/views/chat/index.pug index 82f7e82..990552f 100644 --- a/app/views/chat/index.pug +++ b/app/views/chat/index.pug @@ -1,5 +1,12 @@ extends layouts/room block content - h1 Chat Home - \ No newline at end of file + .content-block.uk-height-1-1.uk-overflow-auto + + h1 #{site.name} Chat + + p You can #[a(href='/chat/room/create') create] public and private chat rooms. A public room is listed in the public room directory, shown below. Private rooms are not listed in the directory and are unable to be found in search. + + p Rooms can be open, which means anyone can join them if they have them link. Rooms can also be closed, which means the room owner must invite people to join (and they have to accept). + + h2 Public Rooms \ No newline at end of file diff --git a/app/views/chat/layouts/room.pug b/app/views/chat/layouts/room.pug index 1cb9945..a91c437 100644 --- a/app/views/chat/layouts/room.pug +++ b/app/views/chat/layouts/room.pug @@ -5,15 +5,20 @@ block content-container mixin renderRoomList (rooms) each room in ownedChatRooms li.uk-active - a(href=`/chat/${room._id}`)= room.name + a(href=`/chat/room/${room._id}`)= room.name section.site-chat-section div(uk-grid).uk-height-1-1 - div(class="uk-width-1-1 uk-width-1-5@l uk-flex-last uk-flex-first@l") + div(class="uk-width-1-1 uk-width-1-5@l uk-flex-last uk-flex-first@l").uk-height-1-1.uk-overflow-auto .content-block.uk-border-rounded.uk-margin if Array.isArray(ownedChatRooms) && (ownedChatRooms.length > 0) ul#room-list.uk-nav.uk-nav-default - li.uk-nav-header Your Rooms + li.uk-nav-header + div(uk-grid).uk-grid-small + .uk-width-expand Your Rooms + .uk-width-auto + a(href='/chat/room/create', uk-tooltip="Create new chat room...").uk-link-reset + i.fas.fa-plus +renderRoomList(ownedChatRooms) else div You don't own any chat rooms. @@ -30,7 +35,7 @@ block content-container #chat-room.uk-height-1-1 block content - div(class="uk-width-1-1 uk-width-1-5@l") + div(class="uk-width-1-1 uk-width-1-5@l").uk-height-1-1.uk-overflow-auto .content-block.uk-border-rounded if chatRoom if Array.isArray(chatRoom.members) && (chatRoom.members.length > 0) diff --git a/app/views/chat/room-editor.pug b/app/views/chat/room-editor.pug deleted file mode 100644 index 92d63a6..0000000 --- a/app/views/chat/room-editor.pug +++ /dev/null @@ -1,54 +0,0 @@ -extends layouts/room -block content - - form(method="POST", action="/chat").uk-form - .uk-card.uk-card-default.uk-card-small - .uk-card-header - h1.uk-card-title Create Chat Room - .uk-card-body - .uk-margin - label(for="name").uk-form-label Room name - input(id="name", name="name", type="text", placeholder="Enter room name").uk-input - - .uk-margin - label(for="description").uk-form-label Room description - textarea(id="description", name="description", rows="2", placeholder="Enter room description").uk-textarea - - .uk-margin - label(for="policy").uk-form-label Room policy - textarea(id="policy", name="policy", rows="2", placeholder="Enter room use policy").uk-textarea - - .uk-margin - div(uk-grid) - .uk-width-auto - fieldset - legend Room Visibility - div(uk-grid).uk-grid-small.uk-flex-middle - .uk-width-auto - label - input(id="is-public", name="visibility", type="radio", value="public", checked).uk-radio - | Public - .ui-width-auto - label - input(id="is-private", name="visibility", type="radio", value="private").uk-radio - | Private - - .uk-width-auto - fieldset - legend Membership Policy - div(uk-grid).uk-grid-small.uk-flex-middle - .uk-width-auto - label - input(id="membership-open", name="policy", type="radio", value="open", checked).uk-radio - | Open - .uk-width-auto - label - input(id="membership-closed", name="policy", type="radio", value="closed").uk-radio - | Closed - - .uk-card-footer - div(uk-grid) - .uk-width-expand - +renderBackButton() - .uk-width-auto - button(type="submit").uk-button.uk-button-primary.uk-border-rounded Create room \ No newline at end of file diff --git a/app/views/chat/room/editor.pug b/app/views/chat/room/editor.pug new file mode 100644 index 0000000..7c56b46 --- /dev/null +++ b/app/views/chat/room/editor.pug @@ -0,0 +1,55 @@ +extends ../layouts/room +block content + + .content-block.uk-height-1-1.uk-overflow-auto + form(method="POST", action="/chat").uk-form + .uk-card.uk-card-default.uk-card-small + .uk-card-header + h1.uk-card-title Create Chat Room + .uk-card-body + .uk-margin + label(for="name").uk-form-label Room name + input(id="name", name="name", type="text", placeholder="Enter room name").uk-input + + .uk-margin + label(for="description").uk-form-label Room description + textarea(id="description", name="description", rows="2", placeholder="Enter room description").uk-textarea + + .uk-margin + label(for="policy").uk-form-label Room policy + textarea(id="policy", name="policy", rows="2", placeholder="Enter room use policy").uk-textarea + + .uk-margin + div(uk-grid) + .uk-width-auto + fieldset + legend Room Visibility + div(uk-grid).uk-grid-small.uk-flex-middle + .uk-width-auto + label + input(id="is-public", name="visibility", type="radio", value="public", checked).uk-radio + | Public + .ui-width-auto + label + input(id="is-private", name="visibility", type="radio", value="private").uk-radio + | Private + + .uk-width-auto + fieldset + legend Membership Policy + div(uk-grid).uk-grid-small.uk-flex-middle + .uk-width-auto + label + input(id="membership-open", name="policy", type="radio", value="open", checked).uk-radio + | Open + .uk-width-auto + label + input(id="membership-closed", name="policy", type="radio", value="closed").uk-radio + | Closed + + .uk-card-footer + div(uk-grid) + .uk-width-expand + +renderBackButton() + .uk-width-auto + button(type="submit").uk-button.uk-button-primary.uk-border-rounded Create room \ No newline at end of file diff --git a/app/views/chat/view.pug b/app/views/chat/room/view.pug similarity index 93% rename from app/views/chat/view.pug rename to app/views/chat/room/view.pug index 73bbfa1..35121d0 100644 --- a/app/views/chat/view.pug +++ b/app/views/chat/room/view.pug @@ -1,8 +1,8 @@ -extends layouts/room +extends ../layouts/room block content - include components/input-form - include components/message + include ../components/input-form + include ../components/message #site-chat-container.uk-flex.uk-flex-column.uk-height-1-1 div(uk-grid).uk-flex-middle.chat-menubar