Browse Source

scooted room views into chat/room

develop^2
Rob Colbert 2 years ago
parent
commit
6e672f8262
  1. 35
      app/controllers/chat.js
  2. 11
      app/views/chat/index.pug
  3. 13
      app/views/chat/layouts/room.pug
  4. 54
      app/views/chat/room-editor.pug
  5. 55
      app/views/chat/room/editor.pug
  6. 6
      app/views/chat/room/view.pug

35
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');

11
app/views/chat/index.pug

@ -1,5 +1,12 @@
extends layouts/room
block content
h1 Chat Home
.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

13
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)

54
app/views/chat/room-editor.pug

@ -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

55
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

6
app/views/chat/view.pug → 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
Loading…
Cancel
Save