Skip to content

Commit b86f8db

Browse files
committed
realese feature
1 parent 362b2c8 commit b86f8db

File tree

3 files changed

+103
-29
lines changed

3 files changed

+103
-29
lines changed

public/js/index.js

Lines changed: 85 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,6 @@ import uiElemsWithoutJquery from './lib/editor/ui-elems-without-jquery'
8181
import { emojifyImageDir } from './lib/editor/constants'
8282
import modeType from './lib/modeType'
8383
import appState from './lib/appState'
84-
//import { isLogicalNot } from 'vega-lite/build/src/logical'
8584

8685
require('../vendor/showup/showup')
8786

@@ -259,6 +258,7 @@ const statusType = {
259258
// global vars
260259
window.loaded = false
261260
let isLogin = false
261+
let blockSourceView = false
262262
let needRefresh = false
263263
let isDirty = false
264264
let editShown = false
@@ -293,6 +293,7 @@ const lastInfo = {
293293
}
294294
let personalInfo = {}
295295
let onlineUsers = []
296+
let currentPermission = ''
296297
const fileTypes = {
297298
pl: 'perl',
298299
cgi: 'perl',
@@ -428,9 +429,7 @@ Visibility.change(function (e, state) {
428429

429430
// when page ready
430431
$(document).ready(function () {
431-
if (ui.toolbar.edit.data('blockSource') && isLogin === false) { replaceUrl(window.location.href) }
432-
433-
console.log("personal info", onlineUsers)
432+
if (ui.toolbar.edit.data('blockSource') && !isLogin) { replaceUrl(window.location.href) }
434433

435434
idle.checkAway()
436435
checkResponsive()
@@ -480,14 +479,14 @@ $(document).ready(function () {
480479

481480
key.filter = function (e) { return true }
482481
key('ctrl+alt+e', function (e) {
483-
if (ui.toolbar.edit.data('blockSource') && isLogin === false) return
482+
if (blockSourceView) return
484483
changeMode(modeType.edit)
485484
})
486485
key('ctrl+alt+v', function (e) {
487486
changeMode(modeType.view)
488487
})
489488
key('ctrl+alt+b', function (e) {
490-
if (ui.toolbar.both.data('blockSource') && isLogin === false) return
489+
if (blockSourceView) return
491490
changeMode(modeType.both)
492491
})
493492
// toggle-dropdown
@@ -521,18 +520,79 @@ function replaceUrl (url) {
521520
}
522521

523522
//
524-
function disableToolbarButtons (isLogin, elems) {
525-
if (isLogin === false) {
526-
elems.edit.setAttribute('disabled', null)
527-
elems.edit.setAttribute('title', 'You have no rights to edit this note')
528-
elems.both.setAttribute('disabled', null)
529-
elems.both.setAttribute('title', 'You have no rights to edit this note')
530-
} else {
531-
elems.edit.removeAttribute('disabled')
532-
elems.both.removeAttribute('disabled')
523+
function allowVisibleSource (isLogin, permission) {
524+
console.log('isWokr?', isLogin, permission)
525+
switch(permission) {
526+
case 'freely':
527+
blockSourceView = false
528+
break
529+
case 'editable':
530+
if (!isLogin) {
531+
blockSourceView = true
532+
uiByNativeJS.toolbar.edit.setAttribute('disabled', null)
533+
uiByNativeJS.toolbar.edit.setAttribute('title', 'You have no rights to edit this note')
534+
uiByNativeJS.toolbar.both.setAttribute('disabled', null)
535+
uiByNativeJS.toolbar.both.setAttribute('title', 'You have no rights to edit this note')
536+
} else {
537+
blockSourceView = false
538+
uiByNativeJS.toolbar.edit.removeAttribute('disabled')
539+
uiByNativeJS.toolbar.edit.setAttribute('title', 'Edit (Ctrl+Alt+E)')
540+
uiByNativeJS.toolbar.both.removeAttribute('disabled')
541+
uiByNativeJS.toolbar.both.setAttribute('title', 'Both (Ctrl+Alt+B)')
542+
}
543+
break
544+
case 'limited':
545+
if (!isLogin) {
546+
blockSourceView = true
547+
uiByNativeJS.toolbar.edit.setAttribute('disabled', null)
548+
uiByNativeJS.toolbar.edit.setAttribute('title', 'You have no rights to edit this note')
549+
uiByNativeJS.toolbar.both.setAttribute('disabled', null)
550+
uiByNativeJS.toolbar.both.setAttribute('title', 'You have no rights to edit this note')
551+
} else {
552+
blockSourceView = false
553+
uiByNativeJS.toolbar.edit.removeAttribute('disabled')
554+
uiByNativeJS.toolbar.edit.setAttribute('title', 'Edit (Ctrl+Alt+E)')
555+
uiByNativeJS.toolbar.both.removeAttribute('disabled')
556+
uiByNativeJS.toolbar.both.setAttribute('title', 'Both (Ctrl+Alt+B)')
557+
}
558+
break
559+
case 'locked':
560+
if (personalInfo.userid && window.owner && personalInfo.userid === window.owner) {
561+
blockSourceView = false
562+
} else {
563+
blockSourceView = true
564+
uiByNativeJS.toolbar.edit.setAttribute('disabled', null)
565+
uiByNativeJS.toolbar.edit.setAttribute('title', 'You have no rights to edit this note')
566+
uiByNativeJS.toolbar.both.setAttribute('disabled', null)
567+
uiByNativeJS.toolbar.both.setAttribute('title', 'You have no rights to edit this note')
568+
}
569+
break
570+
case 'protected':
571+
if (personalInfo.userid && window.owner && personalInfo.userid === window.owner) {
572+
blockSourceView = false
573+
} else {
574+
blockSourceView = true
575+
uiByNativeJS.toolbar.edit.setAttribute('disabled', null)
576+
uiByNativeJS.toolbar.edit.setAttribute('title', 'You have no rights to edit this note')
577+
uiByNativeJS.toolbar.both.setAttribute('disabled', null)
578+
uiByNativeJS.toolbar.both.setAttribute('title', 'You have no rights to edit this note')
579+
}
580+
break
581+
case 'private':
582+
if (personalInfo.userid && window.owner && personalInfo.userid === window.owner) {
583+
blockSourceView = false
584+
} else {
585+
blockSourceView = true
586+
uiByNativeJS.toolbar.edit.setAttribute('disabled', null)
587+
uiByNativeJS.toolbar.edit.setAttribute('title', 'You have no rights to edit this note')
588+
uiByNativeJS.toolbar.both.setAttribute('disabled', null)
589+
uiByNativeJS.toolbar.both.setAttribute('title', 'You have no rights to edit this note')
590+
}
591+
break
533592
}
534593
}
535594

595+
//checking is user log in
536596
function userIsLogin (userPersonalInfo) {
537597
if (userPersonalInfo.hasOwnProperty('login')) {
538598
if (userPersonalInfo.login === true) {
@@ -1612,15 +1672,14 @@ function importFromUrl (url) {
16121672
ui.toolbar.mode.click(function () {
16131673
if (personalInfo.userid && window.owner && personalInfo.userid === window.owner) {
16141674
toggleMode()
1615-
} else if (ui.toolbar.mode.data('blockSource')) return
1675+
} else if (blockSourceView) return
16161676
toggleMode()
16171677
})
16181678
// edit
16191679
ui.toolbar.edit.click(function () {
16201680
if (personalInfo.userid && window.owner && personalInfo.userid === window.owner) {
1621-
console.dir(personalInfo)
16221681
changeMode(modeType.edit)
1623-
} else if (ui.toolbar.edit.data('blockSource')) return
1682+
} else if (blockSourceView) return
16241683
changeMode(modeType.edit)
16251684
})
16261685
// view
@@ -1631,7 +1690,7 @@ ui.toolbar.view.click(function () {
16311690
ui.toolbar.both.click(function () {
16321691
if (personalInfo.userid && window.owner && personalInfo.userid === window.owner) {
16331692
changeMode(modeType.edit)
1634-
} else if (ui.toolbar.both.data('blockSource')) return
1693+
} else if (blockSourceView) return
16351694
changeMode(modeType.both)
16361695
})
16371696

@@ -2100,6 +2159,7 @@ socket.on('refresh', function (data) {
21002159
editor.setOption('maxLength', editorInstance.config.docmaxlength)
21012160
updateInfo(data)
21022161
updatePermission(data.permission)
2162+
currentPermission = data.permission
21032163
if (!window.loaded) {
21042164
// auto change mode if no content detected
21052165
var nocontent = editor.getValue().length <= 0
@@ -2222,7 +2282,12 @@ socket.on('online users', function (data) {
22222282
if (user.id !== socket.id) { buildCursor(user) } else { personalInfo = user }
22232283
}
22242284
if (ui.toolbar.edit.data('blockSource')) {
2225-
disableToolbarButtons(userIsLogin(personalInfo), uiByNativeJS)
2285+
setTimeout(() => {
2286+
allowVisibleSource(userIsLogin(personalInfo), currentPermission)
2287+
console.log('per in timeout', currentPermission)
2288+
}, 10000)
2289+
//allowVisibleSource(userIsLogin(personalInfo), currentPermission)
2290+
//console.log('per', currentPermission)
22262291
}
22272292
})
22282293
socket.on('user status', function (data) {
@@ -2273,12 +2338,6 @@ socket.on('cursor blur', function (data) {
22732338
}
22742339
})
22752340

2276-
//checked user is login
2277-
async function userPersonalInfo (personalInfo) {
2278-
let userInfo = await personalInfo
2279-
return userInfo
2280-
}
2281-
22822341
var options = {
22832342
valueNames: ['id', 'name'],
22842343
item: '<li class="ui-user-item">' +
Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,20 @@
11
export const uiElemsWithoutJquery = () => ({
2-
edit: document.querySelector('.ui-edit'),
3-
both: document.querySelector('.ui-both')
2+
toolbar: {
3+
edit: document.querySelector('.ui-edit'),
4+
both: document.querySelector('.ui-both')
5+
},
6+
infobar: {
7+
permission: {
8+
permission: document.querySelector('.ui-permission'),
9+
label: document.querySelector('.ui-permission-label'),
10+
freely: document.querySelector('.ui-permission-freely'),
11+
editable: document.querySelector('.ui-permission-editable'),
12+
locked: document.querySelector('.ui-permission-locked'),
13+
private: document.querySelector('.ui-permission-private'),
14+
limited: document.querySelector('.ui-permission-limited'),
15+
protected: document.querySelector('.ui-permission-protected')
16+
}
17+
}
418
})
519

620
export default uiElemsWithoutJquery

public/views/codimd/header.ejs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,11 +90,12 @@
9090
<div class="collapse navbar-collapse">
9191
<ul class="nav navbar-nav navbar-form navbar-left" style="padding:0;">
9292
<div class="btn-group" data-toggle="buttons">
93+
<div class="<%= Object.keys(permission) %>"></div>
9394
<% if(!allowVisibleSource) { %>
9495
<label class="btn btn-default ui-edit" data-block-source="<%= !allowVisibleSource %>" title="<%= __('Edit') %> (Ctrl+Alt+E)">
9596
<input type="radio" autocomplete="off"><i class="fa fa-pencil"></i>
9697
</label>
97-
<label class="btn btn-default ui-both" data-block-source="<%= !allowVisibleSource %>" title="<%= __('You have no rights to edit this note') %>">
98+
<label class="btn btn-default ui-both" data-block-source="<%= !allowVisibleSource %>" title="<%= __('Both') %> (Ctrl+Alt+B)">
9899
<input type="radio" autocomplete="off"><i class="fa fa-columns"></i>
99100
</label>
100101
<% } else { %>

0 commit comments

Comments
 (0)