From d81e83545911dc9bb751be568e86bc424c90cadf Mon Sep 17 00:00:00 2001 From: Sukhamjot Singh Date: Tue, 2 Aug 2022 19:11:45 +0530 Subject: [PATCH] create channel(without thumnail) --- webui-src/app/channels/channel_view.js | 76 ++++++++++++++++++- webui-src/app/channels/channels.js | 100 ++++++++++++++++--------- webui-src/app/forums/forum_view.js | 4 +- webui-src/app/forums/forums.js | 2 +- 4 files changed, 142 insertions(+), 40 deletions(-) diff --git a/webui-src/app/channels/channel_view.js b/webui-src/app/channels/channel_view.js index 8427ab7..d7b5ea8 100644 --- a/webui-src/app/channels/channel_view.js +++ b/webui-src/app/channels/channel_view.js @@ -73,6 +73,77 @@ async function parsefile(file, type) { return ansList; } +function createchannel() { + let title; + let body; + let identity; + return { + oninit: (vnode) => { + if (vnode.attrs.authorId) { + identity = vnode.attrs.authorId[0]; + } + }, + view: (vnode) => + m('.widget', [ + m('h3', 'Create Channel'), + m('hr'), + m('input[type=text][placeholder=Title]', { + oninput: (e) => (title = e.target.value), + }), + m('label[for=tags]', 'Select identity'), + m( + 'select[id=idtags]', + { + value: identity, + onchange: (e) => { + identity = vnode.attrs.authorId[e.target.selectedIndex]; + }, + }, + [ + vnode.attrs.authorId && + vnode.attrs.authorId.map((o) => + m( + 'option', + { value: o }, + rs.userList.userMap[o] ? rs.userList.userMap[o].toLocaleString() : 'No Signature' + ) + ), + ] + ), + m('textarea[rows=5][placeholder=Description]', { + style: { width: '90%', display: 'block' }, + oninput: (e) => (body = e.target.value), + value: body, + }), + m( + 'button', + { + onclick: async () => { + const res = await rs.rsJsonApiRequest('/rsgxschannels/createChannelV2', { + name: title, + description: body, + // thumbnail: {}, + ...(Number(identity) !== 0 && { authorId: identity }), + }); + if (res.body.retval) { + util.updatedisplaychannels(res.body.channelId); + m.redraw(); + } + res.body.retval === false + ? util.popupmessage([m('h3', 'Error'), m('hr'), m('p', res.body.errorMessage)]) + : util.popupmessage([ + m('h3', 'Success'), + m('hr'), + m('p', 'Channel created successfully'), + ]); + }, + }, + 'Create' + ), + ]), + }; +} + const AddPost = () => { let content = ''; let ptitle = ''; @@ -111,7 +182,7 @@ const AddPost = () => { for (let i = 0; i < e.target.files.length; i++) { await parsefile(e.target.files[i], 'multiple'); } - // console.log(filesUploadHashes.PostFiles, filesUploadHashes.PostFiles.length); + console.log(filesUploadHashes.PostFiles, filesUploadHashes.PostFiles.length); if (filesUploadHashes.PostFiles.length === e.target.files.length) { for (let i = 0; i < e.target.files.length; i++) { @@ -153,6 +224,8 @@ const AddPost = () => { m('hr'), m('p', 'Post added successfully'), ]); + util.updatedisplaychannels(vnode.attrs.chanId); + m.redraw(); } }, }, @@ -632,4 +705,5 @@ const PostView = () => { module.exports = { ChannelView, PostView, + createchannel, }; diff --git a/webui-src/app/channels/channels.js b/webui-src/app/channels/channels.js index b4ef882..7af9d17 100644 --- a/webui-src/app/channels/channels.js +++ b/webui-src/app/channels/channels.js @@ -3,6 +3,8 @@ const widget = require('widgets'); const rs = require('rswebui'); const util = require('channels/channels_util'); const viewUtil = require('channels/channel_view'); +const peopleUtil = require('people/people_util'); + const getChannels = { All: [], @@ -32,46 +34,72 @@ const sections = { OtherChannels: require('channels/other_channels'), }; -const Layout = { - oninit: () => { - rs.setBackgroundTask(getChannels.load, 5000, () => { - // return m.route.get() === '/files/files'; - }); - }, - // onupdate: getChannels.load, - view: (vnode) => - m('.tab-page', [ - Object.prototype.hasOwnProperty.call(vnode.attrs.pathInfo, 'mMsgId') - ? '' - : Object.prototype.hasOwnProperty.call(vnode.attrs.pathInfo, 'mGroupId') - ? m(util.SearchBar, { - category: 'posts', - channelId: vnode.attrs.pathInfo.mGroupId, - }) - : m(util.SearchBar, { - category: 'channels', - }), - m(widget.Sidebar, { - tabs: Object.keys(sections), - baseRoute: '/channels/', - }), - m( - '.channel-node-panel', +const Layout = () => { + let ownId; + return { + oninit: () => { + rs.setBackgroundTask(getChannels.load, 5000, () => { + // return m.route.get() === '/files/files'; + }); + peopleUtil.ownIds((data) => { + ownId = data; + for (let i = 0; i < ownId.length; i++) { + if (Number(ownId[i]) === 0) { + ownId.splice(i, 1); + } + } + ownId.unshift(0); + }); + }, + // onupdate: getChannels.load, + view: (vnode) => + m('.tab-page', [ Object.prototype.hasOwnProperty.call(vnode.attrs.pathInfo, 'mMsgId') - ? m(viewUtil.PostView, { - msgId: vnode.attrs.pathInfo.mMsgId, + ? '' + : Object.prototype.hasOwnProperty.call(vnode.attrs.pathInfo, 'mGroupId') + ? m(util.SearchBar, { + category: 'posts', channelId: vnode.attrs.pathInfo.mGroupId, }) - : Object.prototype.hasOwnProperty.call(vnode.attrs.pathInfo, 'mGroupId') - ? m(viewUtil.ChannelView, { - id: vnode.attrs.pathInfo.mGroupId, - }) - : m(sections[vnode.attrs.pathInfo.tab], { - list: getChannels[vnode.attrs.pathInfo.tab], - }) - ), - ]), + : m(util.SearchBar, { + category: 'channels', + }), + m( + 'button', + { + style: { fontSize: '1.2em', width: '200px' }, + onclick: () => + util.popupmessage( + m(viewUtil.createchannel, { + authorId: ownId, + }) + ), + }, + 'Create Channel' + ), + m(widget.Sidebar, { + tabs: Object.keys(sections), + baseRoute: '/channels/', + }), + m( + '.channel-node-panel', + + Object.prototype.hasOwnProperty.call(vnode.attrs.pathInfo, 'mMsgId') + ? m(viewUtil.PostView, { + msgId: vnode.attrs.pathInfo.mMsgId, + channelId: vnode.attrs.pathInfo.mGroupId, + }) + : Object.prototype.hasOwnProperty.call(vnode.attrs.pathInfo, 'mGroupId') + ? m(viewUtil.ChannelView, { + id: vnode.attrs.pathInfo.mGroupId, + }) + : m(sections[vnode.attrs.pathInfo.tab], { + list: getChannels[vnode.attrs.pathInfo.tab], + }) + ), + ]), + }; }; module.exports = { diff --git a/webui-src/app/forums/forum_view.js b/webui-src/app/forums/forum_view.js index f9c74e8..decca49 100644 --- a/webui-src/app/forums/forum_view.js +++ b/webui-src/app/forums/forum_view.js @@ -4,7 +4,7 @@ const util = require('forums/forums_util'); const peopleUtil = require('people/people_util'); const { updatedisplayforums } = require('./forums_util'); -function addpost() { +function createforum() { let title; let body; let identity; @@ -508,5 +508,5 @@ const ForumView = () => { module.exports = { ForumView, ThreadView, - addpost, + createforum, }; diff --git a/webui-src/app/forums/forums.js b/webui-src/app/forums/forums.js index 773d434..9c3b528 100644 --- a/webui-src/app/forums/forums.js +++ b/webui-src/app/forums/forums.js @@ -60,7 +60,7 @@ const Layout = () => { style: {fontSize: '1.2em', width: '200px'}, onclick: () => util.popupmessage( - m(viewUtil.addpost, { + m(viewUtil.createforum, { authorId: ownId, }) ),