From 33fe35f9639b98a55b079b32be37e1fb78eb3a5e Mon Sep 17 00:00:00 2001 From: Sukhamjot Singh Date: Tue, 13 Sep 2022 23:23:00 +0530 Subject: [PATCH] confirm download,fixed bug --- webui-src/app/channels/channel.css | 14 +++-- webui-src/app/channels/channel_view.js | 63 ++++++++++++++++++----- webui-src/app/config/config_network.js | 26 +++------- webui-src/app/files/files.css | 17 +++++- webui-src/app/files/files_downloads.js | 1 + webui-src/app/files/files_util.js | 2 +- webui-src/app/files/friends_files.js | 71 +++++++++++++++++++------- 7 files changed, 137 insertions(+), 57 deletions(-) diff --git a/webui-src/app/channels/channel.css b/webui-src/app/channels/channel.css index 42781d9..17f3ada 100644 --- a/webui-src/app/channels/channel.css +++ b/webui-src/app/channels/channel.css @@ -97,7 +97,15 @@ table.comments td:nth-child(2) { table.comments tr { height: 40px; } - +table.files th:nth-child(1) { + width: 40%; +} +table.files th:nth-child(3) { + width: 50%; +} +table.files td { + word-wrap: break-word; +} /* #options{ width: 100px; text-align: center; @@ -105,10 +113,10 @@ table.comments tr { margin-left: 20px; height: 40px; } */ -#mtags{ +#mtags { width: 160px; text-align: center; font-size: medium; margin-left: 10px; height: 40px; -} \ No newline at end of file +} diff --git a/webui-src/app/channels/channel_view.js b/webui-src/app/channels/channel_view.js index 70199b3..894456e 100644 --- a/webui-src/app/channels/channel_view.js +++ b/webui-src/app/channels/channel_view.js @@ -687,6 +687,7 @@ const PostView = () => { } voteIdentity = ownId[0]; }); + fileDown.Downloads.loadStatus(); // for retrieving downloading files. }, view: (v) => m('.widget', { key: v.attrs.msgId }, [ @@ -717,20 +718,54 @@ const PostView = () => { 'button', { style: { fontSize: '0.9em' }, - onclick: async () => { - filesInfo[file.mHash] - ? filesInfo[file.mHash].retval - ? '' - : (await rs.rsJsonApiRequest('/rsFiles/FileRequest', { - fileName: file.mName, - hash: file.mHash, - flags: util.RS_FILE_REQ_ANONYMOUS_ROUTING, - size: { - xstr64: file.mSize.xstr64, - }, - })) && m.redraw() - : ''; - }, + onclick: async () => + widget.popupMessage([ + m('p', 'Start Download?'), + m( + 'button', + { + onclick: async () => { + if (filesInfo[file.mHash] && !filesInfo[file.mHash].retval) { + const res = await rs.rsJsonApiRequest('/rsFiles/FileRequest', { + fileName: file.mName, + hash: file.mHash, + flags: util.RS_FILE_REQ_ANONYMOUS_ROUTING, + size: { + xstr64: file.mSize.xstr64, + }, + }); + res.body.retval === false + ? widget.popupMessage([ + m('h3', 'Error'), + m('hr'), + m('p', res.body.errorMessage), + ]) + : widget.popupMessage([ + m('h3', 'Success'), + m('hr'), + m('p', 'Download Started'), + ]); + m.redraw(); + } + }, + }, + 'Start Download' + ), + ]), + // { + // filesInfo[file.mHash] + // ? filesInfo[file.mHash].retval + // ? '' + // : (await rs.rsJsonApiRequest('/rsFiles/FileRequest', { + // fileName: file.mName, + // hash: file.mHash, + // flags: util.RS_FILE_REQ_ANONYMOUS_ROUTING, + // size: { + // xstr64: file.mSize.xstr64, + // }, + // })) && m.redraw() + // : ''; + // }, }, filesInfo[file.mHash] ? filesInfo[file.mHash].retval diff --git a/webui-src/app/config/config_network.js b/webui-src/app/config/config_network.js index 9b84153..f6d821f 100644 --- a/webui-src/app/config/config_network.js +++ b/webui-src/app/config/config_network.js @@ -6,28 +6,16 @@ const util = require('config/config_util'); // for future use /* eslint-disable no-unused-vars */ const SetNwMode = () => { - let mode = undefined; - let sslId = undefined; - const setMode = () => rs.rsJsonApiRequest('/'); + let sslId; return { - oninit: util.getSslId().then((val) => { - sslId = val; - rs.rsJsonApiRequest('/'); - }), + oninit: async () => { + // const res = await rs.rsJsonApiRequest('/rsPeers/getOwnId'); + console.log(util.getSslId()); + }, view: () => [ m('p', 'Network mode:'), - m( - 'select', - { - oninput: (e) => (mode = e.target.value), - value: mode, - onchange: setMode, - }, - ['Discovery on(recommended)', 'Discovery off'].map((val, i) => - m('option[value=' + (i + 1) + ']', val) - ) - ), + ], }; }; @@ -130,7 +118,7 @@ const Component = () => { m('.grid-2col', [ m(SetLimits), m(SetOpMode), - // m(SetNwMode), + m(SetNwMode), ]), ]), }; diff --git a/webui-src/app/files/files.css b/webui-src/app/files/files.css index 3914221..a5be344 100644 --- a/webui-src/app/files/files.css +++ b/webui-src/app/files/files.css @@ -62,4 +62,19 @@ table.myfiles th:nth-child(2) { } table.myfiles td:nth-child(2) { text-align: start; -} \ No newline at end of file +} +table.friendsfiles td { + word-wrap: break-word; +} +table.friendsfiles th:nth-child(1) { + width: 2%; +} +table.friendsfiles th:nth-child(2) { + width: 50%; +} +table.friendsfiles th:nth-child(4) { + width: 40%; +} +table.friendsfiles td:nth-child(2) { + text-align: start; +} diff --git a/webui-src/app/files/files_downloads.js b/webui-src/app/files/files_downloads.js index 937f055..42d0063 100644 --- a/webui-src/app/files/files_downloads.js +++ b/webui-src/app/files/files_downloads.js @@ -169,5 +169,6 @@ const Component = () => { module.exports = { Component, + Downloads, list: Downloads.statusMap, }; diff --git a/webui-src/app/files/files_util.js b/webui-src/app/files/files_util.js index 6278c49..16e8a11 100644 --- a/webui-src/app/files/files_util.js +++ b/webui-src/app/files/files_util.js @@ -295,7 +295,7 @@ const MyFilesTable = () => { const FriendsFilesTable = () => { return { view: (v) => - m('table.myfiles', [ + m('table.friendsfiles', [ m('tr', [ m('th', ''), m('th', 'Friends Directories'), diff --git a/webui-src/app/files/friends_files.js b/webui-src/app/files/friends_files.js index ac5230b..8676c15 100644 --- a/webui-src/app/files/friends_files.js +++ b/webui-src/app/files/friends_files.js @@ -1,6 +1,8 @@ const m = require('mithril'); const rs = require('rswebui'); const util = require('files/files_util'); +const widget = require('widgets'); +const fileDown = require('files/files_downloads'); function displayfiles() { const childrenList = []; // stores children details @@ -75,26 +77,57 @@ function displayfiles() { isFile && m( 'td', - m( - 'button', - { - style: { fontSize: '0.9em' }, - onclick: async () => { - haveFile - ? '' - : await rs.rsJsonApiRequest('/rsFiles/FileRequest', { - fileName: parStruct.details.name, - hash: parStruct.details.hash, - flags: util.RS_FILE_REQ_ANONYMOUS_ROUTING, - size: { - xstr64: parStruct.details.size.xstr64, - }, - }); - }, - }, + // using the file from files_util to display download. + fileDown.list[parStruct.details.hash] + ? m(util.File, { + info: fileDown.list[parStruct.details.hash], + direction: 'down', + transferred: fileDown.list[parStruct.details.hash].transfered.xint64, + parts: [], + }) + : m( + 'button', + { + style: { fontSize: '0.9em' }, + onclick: async () => { + widget.popupMessage([ + m('p', 'Start Download?'), + m( + 'button', + { + onclick: async () => { + if (!haveFile) { + const res = await rs.rsJsonApiRequest('/rsFiles/FileRequest', { + fileName: parStruct.details.name, + hash: parStruct.details.hash, + flags: util.RS_FILE_REQ_ANONYMOUS_ROUTING, + size: { + xstr64: parStruct.details.size.xstr64, + }, + }); + res.body.retval === false + ? widget.popupMessage([ + m('h3', 'Error'), + m('hr'), + m('p', res.body.errorMessage), + ]) + : widget.popupMessage([ + m('h3', 'Success'), + m('hr'), + m('p', 'Download Started'), + ]); + m.redraw(); + } + }, + }, + 'Start Download' + ), + ]); + }, + }, - haveFile ? 'Open File' : ['Download', m('i.fas.fa-download')] - ) + haveFile ? 'Open File' : ['Download', m('i.fas.fa-download')] + ) ), ]), parStruct.showChild && // recursive call to show children