From b1d0a0f095fe1e04327d91d64f6ca7078cc0d989 Mon Sep 17 00:00:00 2001 From: senta_mandutz Date: Tue, 23 Jul 2019 16:07:14 +0200 Subject: [PATCH 1/2] bookmark without color change --- public/routes/bookmark.js | 18 ++++++++++++-- public/routes/home.js | 5 +++- public/routes/msgCard.js | 51 +++++++++++++++++++++++++++++---------- public/style/style.css | 5 ++-- public/style/style.less | 7 ++++++ 5 files changed, 67 insertions(+), 19 deletions(-) diff --git a/public/routes/bookmark.js b/public/routes/bookmark.js index 4da2502..c627af4 100644 --- a/public/routes/bookmark.js +++ b/public/routes/bookmark.js @@ -36,7 +36,21 @@ const BookmarkRouter = { }, getMessages: function(){ - var _usrid = "5d360f06b8f3ce67d12ccc92"; + var arr = auth.bookmarks; + console.log("arr: "+arr+" auth.bookmarks: "+auth.bookmarks); + _messagelist.splice(0, _messagelist.length); + _messagelist.push.apply(_messagelist, arr); + for (var e in arr) { + if (!_messages[arr[e]]) { + //arr[e] =arr[e].replace(/\[/g, '').replace(/\"/g, '').replace(/\]/g, '') + console.log("getinsertmessage: "+ arr[e]); + get_insert_message(arr[e]); + } + } + + + + /*var _usrid = auth.user; $.ajax({ url: "api/usr/id/" + _usrid, method: "GET" @@ -59,7 +73,7 @@ const BookmarkRouter = { function have_error(err) { console.log("error: " + err.responseText); console.log(err); - } + }*/ } }, mounted: function (){ diff --git a/public/routes/home.js b/public/routes/home.js index e8f3a67..7fc092c 100644 --- a/public/routes/home.js +++ b/public/routes/home.js @@ -8,6 +8,7 @@ const HomeRouter = { v-for="id in messagelist.slice().reverse()" :key="id" :msg="messages[id] || {}" + :isBookmark="bookmarkArray[id]" > `, @@ -16,7 +17,8 @@ const HomeRouter = { messagelist: _messagelist, messages: _messages, isSearchActiv: _isSearchActiv, - isSubscripeButtonActiv: _isSubscripeButtonActiv + isSubscripeButtonActiv: _isSubscripeButtonActiv, + bookmarkArray: auth.bookmarks, }; }, methods: { @@ -29,6 +31,7 @@ const HomeRouter = { _isSearchActiv = false; } + }, mounted: function () { this.list_messages(); diff --git a/public/routes/msgCard.js b/public/routes/msgCard.js index 1152e9d..e20fcbc 100644 --- a/public/routes/msgCard.js +++ b/public/routes/msgCard.js @@ -2,7 +2,7 @@ Vue.component('MsgCard', { template: `
{{ msg.subject }} -
{{msg._id}}
+
{{msg._id}}
{{ msg.message }}
@@ -12,25 +12,36 @@ Vue.component('MsgCard', {
`, - props: ['msg'], + props: ['msg', 'isBookmark'], data: function () { return { - isActive: false, + isActive: this.isBookmark, + isActive_: 0, + msgid: this.msg._id }; }, methods: { - myFilter: function(_messageid) { + myFilter: function (_messageid) { //var _messageid = $("#msgid").text(); + if (this.isActive == true) { + var index = auth.bookmarks.indexOf(_messageid); - var _bookmark = auth.bookmarks; - _bookmark.push(_messageid); - console.log("msgid"+_bookmark); - var _userid = "5d360f06b8f3ce67d12ccc92"; + if (index > -1) { + auth.bookmarks.splice(index, 1); + } + this.isActive = false; + } else { + console.log("_messsageid: "+_messageid+" bookmarks: "+auth.bookmarks); + auth.bookmarks.push(_messageid); + this.isActive =true; + } + /*console.log("msgid"+_bookmark); + var _userid = auth.user; this.isActive = !this.isActive; if(this.isActive){ $.ajax({ @@ -50,11 +61,25 @@ Vue.component('MsgCard', { console.log("error: " + err.responseText); console.log(err); } - } + }*/ }, - filterForTag: function(tag) { - console.log("link: " +tag); + filterForTag: function (tag) { + console.log("link: " + tag); searching(tag); }, + isBookmarkActive: function (msgid) { + //console.log("isBookmarkActive(): " + msgid); + if (auth.bookmarks.indexOf(msgid) > -1) { + // $("#bockmark-not-active").css("visibility","hidden"); + // $("#bockmark-active").css("visibility","visible"); + this.isActive = true; + //console.log("isBookmarkActive(): " + this.isActive); + this.isActive_ = 1; + + } + } + }, + beforeMount: function () { + //this.isBookmarkActive(); } }); diff --git a/public/style/style.css b/public/style/style.css index f646ef7..0c1d9b6 100644 --- a/public/style/style.css +++ b/public/style/style.css @@ -241,7 +241,6 @@ button.clearButton { float: right; } } - -.subscribe-btn{ - float:right; +#bockmark-not-active { + visibility: visible; } diff --git a/public/style/style.less b/public/style/style.less index 5420cff..eeb9cf7 100644 --- a/public/style/style.less +++ b/public/style/style.less @@ -284,3 +284,10 @@ button.clearButton{ float: right; } } + +#bockmark-not-active{ + visibility: visible; +} +#bockmark-active{ + //visibility: hidden; +} From 2d4850520daf95cfe8001f670989ad33fb07cd29 Mon Sep 17 00:00:00 2001 From: Erik Roemmelt Date: Tue, 23 Jul 2019 17:22:01 +0200 Subject: [PATCH 2/2] Vue Rerender function --- mong_usr.js | 6 ++---- public/index.html | 15 ++------------ public/routes/auth.js | 8 +++----- public/routes/home.js | 24 +++++++++++------------ public/routes/initGlobals.js | 13 +++++++++++- public/routes/msgCard.js | 38 ++++++++++++++++++++---------------- public/routes/navRoutes.js | 18 +++++++++++++++-- public/routes/profil.js | 30 ++++++++++++++-------------- public/routes/profilCard.js | 11 ++++++----- server/authorization.js | 24 ++++++++++++++++------- 10 files changed, 106 insertions(+), 81 deletions(-) diff --git a/mong_usr.js b/mong_usr.js index 59985bd..21dc06d 100644 --- a/mong_usr.js +++ b/mong_usr.js @@ -1,12 +1,10 @@ db.users.insert([ // author,OHMNEWS2019 - {"_id":"author","name":"Test Author","type":"author","roles":["user","author"],"hash":"sha256","salt":"cy5CkPrplcEze6o4psURhw==","pwd":"Gc8ozlxjEGITkS+fW9tz2xLROzws44s04EOCWuP04qE=","abos":["wichtig","th"],"bookmarks":["th"],}, + {"_id":"author","name":"Test Author","type":"author","roles":{"user":true,"author":true},"hash":"sha256","salt":"cy5CkPrplcEze6o4psURhw==","pwd":"Gc8ozlxjEGITkS+fW9tz2xLROzws44s04EOCWuP04qE=","abos":["wichtig","th"],"bookmarks":["th"],}, // admin,oZuse1 - {"_id":"admin","name":"Test Admin","type":"admin","roles":["user","author","admin"],"hash":"sha256","salt":"PoIUHbDp7tP34ji31iQ0zw==","pwd":"mJpIfIksYs6LJJwYRBemFKqR6TacsSl2E0ZtpO1GMuk=","abos":["wichtig","th"],"bookmarks":["wichtig"],}, + {"_id":"admin","name":"Test Admin","type":"admin","roles":{"user":true,"author":true,"admin":true},"hash":"sha256","salt":"PoIUHbDp7tP34ji31iQ0zw==","pwd":"mJpIfIksYs6LJJwYRBemFKqR6TacsSl2E0ZtpO1GMuk=","abos":["wichtig","th"],"bookmarks":["wichtig"],}, ]) -db.users.insert({"name":"mustermannmax", "roles":["user"],"abos":[],"bookmarks":[]}) - //var c = require('./server/crypto.js'), // e = {"_id":"writer","hash":"sha256"}; //c.fillLocalAuth(e,"pwd"); diff --git a/public/index.html b/public/index.html index f47097a..ca4ec59 100644 --- a/public/index.html +++ b/public/index.html @@ -95,28 +95,17 @@
- +
diff --git a/public/routes/auth.js b/public/routes/auth.js index 924e92f..8f56f72 100644 --- a/public/routes/auth.js +++ b/public/routes/auth.js @@ -122,6 +122,8 @@ Vue.component('login-panel', { function successful_login(resData) { fillAuthState(resData); // updateUserInDB(); + auth.abos = []; + auth.bookmarks = []; console.info("Correct credentials"); this.closeLoginPanel; @@ -150,6 +152,7 @@ Vue.component('login-panel', { function successful_login(res) { console.info("Re-Auth: Correct credentials"); this.closeLoginPanel; + vueForceRender(); //console.log(res); router.push('/home') @@ -163,10 +166,5 @@ Vue.component('login-panel', { console.log(err); } }, - logout: function() { - clearAuthState(); - $.ajax({ url: "api/logout", method: "POST" }); - this.closeLoginPanel; - }, }, }); diff --git a/public/routes/home.js b/public/routes/home.js index 7fc092c..077e3ed 100644 --- a/public/routes/home.js +++ b/public/routes/home.js @@ -1,17 +1,17 @@ const HomeRouter = { template: ` -
-
- < zurück zu allen Einträgen - - -
-
`, +
+
+ < zurück zu allen Einträgen + + + +
+
`, data: function () { return { messagelist: _messagelist, diff --git a/public/routes/initGlobals.js b/public/routes/initGlobals.js index 631d873..fe9c5ca 100644 --- a/public/routes/initGlobals.js +++ b/public/routes/initGlobals.js @@ -16,6 +16,17 @@ var auth = {}, _isSearchActiv = false, _isSubscripeButtonActiv = false, data = [], - search_data = [] + search_data = [], + // Vue Rerender Key + vueRender = { key:0 }; +const authorRole = 'author'; + +// Global Functions +function vueForceRender() { + if (vueRender.key >= 10) { + vueRender.key = 0; + } + vueRender.key++; +} diff --git a/public/routes/msgCard.js b/public/routes/msgCard.js index e20fcbc..b093abf 100644 --- a/public/routes/msgCard.js +++ b/public/routes/msgCard.js @@ -1,27 +1,31 @@ Vue.component('MsgCard', { - template: `
-
+ template: ` +
+
{{ msg.subject }}
{{msg._id}}
-
- {{ msg.message }}
- #{{ tag }} -
-

-
+ {{ msg.message }}
+ #{{ tag }} +
+
`, + + `, props: ['msg', 'isBookmark'], data: function () { return { isActive: this.isBookmark, isActive_: 0, - msgid: this.msg._id + msgid: this.msg._id, + bookmarkArray: auth.bookmarks, }; }, @@ -29,15 +33,15 @@ Vue.component('MsgCard', { myFilter: function (_messageid) { //var _messageid = $("#msgid").text(); if (this.isActive == true) { - var index = auth.bookmarks.indexOf(_messageid); + var index = this.bookmarkArray.indexOf(_messageid); if (index > -1) { - auth.bookmarks.splice(index, 1); + this.bookmarkArray.splice(index, 1); } this.isActive = false; } else { - console.log("_messsageid: "+_messageid+" bookmarks: "+auth.bookmarks); - auth.bookmarks.push(_messageid); + console.log("_messsageid: "+_messageid+" bookmarks: "+this.bookmarkArray); + this.bookmarkArray.push(_messageid); this.isActive =true; } /*console.log("msgid"+_bookmark); @@ -69,7 +73,7 @@ Vue.component('MsgCard', { }, isBookmarkActive: function (msgid) { //console.log("isBookmarkActive(): " + msgid); - if (auth.bookmarks.indexOf(msgid) > -1) { + if (this.bookmarkArray.indexOf(msgid) > -1) { // $("#bockmark-not-active").css("visibility","hidden"); // $("#bockmark-active").css("visibility","visible"); this.isActive = true; diff --git a/public/routes/navRoutes.js b/public/routes/navRoutes.js index bb1874a..0b3f526 100644 --- a/public/routes/navRoutes.js +++ b/public/routes/navRoutes.js @@ -11,7 +11,7 @@ Vue.component('nav-router', { search - + add_circle @@ -37,7 +37,7 @@ Vue.component('nav-router', { search Search -
  • +
  • add_circle Create Message
  • @@ -53,6 +53,20 @@ Vue.component('nav-router', { `, + data: function() { + return { + isAuthor: this.isAuthorCheck(), + }; + }, + methods: { + isAuthorCheck: function() { + console.info(auth.roles.author === authorRole); + return (auth.roles.author === authorRole); + }, + }, + updated: function() { + this.isAuthorChecked(); + } }); const routes = [ diff --git a/public/routes/profil.js b/public/routes/profil.js index e1540bb..a3f3c89 100644 --- a/public/routes/profil.js +++ b/public/routes/profil.js @@ -2,22 +2,22 @@ const ProfilRouter = { template: `
    -
    - -
    -
    - +
    + +
    +
    + - - - -
    + + + +
    `, data: function () { diff --git a/public/routes/profilCard.js b/public/routes/profilCard.js index 9b50851..bf0662b 100644 --- a/public/routes/profilCard.js +++ b/public/routes/profilCard.js @@ -18,15 +18,15 @@ Vue.component('profil-card', {
    - - + +
    @@ -51,8 +51,8 @@ Vue.component('profil-card', { data: function () { return { auth: auth, - abo: 7, - saved: 3, + abos: auth.abos ? auth.abos.length : '-', + bookmarks: auth.bookmarks ? auth.bookmarks.length : '-', isCardModalActive: false, }; }, @@ -75,6 +75,7 @@ Vue.component('profil-card', { logout: function() { clearAuthState(); $.ajax({ url: "api/logout", method: "POST" }); + vueForceRender(); router.push('/profil'); }, } diff --git a/server/authorization.js b/server/authorization.js index 65ce8d8..7138add 100644 --- a/server/authorization.js +++ b/server/authorization.js @@ -12,6 +12,16 @@ const ldap = require ('./ldap_ohm'), const serverVisibleSession = { user: true, name: true, type: true, mail: true, roles: true, gender: true, deactivated: true, host: true }; const clientVisibleSession = { user: true, name: true, type: true, mail: true, roles: true, gender: true }; +// Return user role, query from found.mail +function getUserRole(found) { + var roles = "user"; + var mail = found.mail; + if (!/\d/.test(mail)) { + // Mail contains no number + roles += ',"author"'; + } + return roles; +} // Fill in session object function fillSession (req, user, roles, cb) { @@ -22,7 +32,7 @@ function fillSession (req, user, roles, cb) { req.session.regenerate (function (err) { if (user !== undefined && ! err) { common.shallowCopy (user, serverVisibleSession, {roles: true}, req.session); - console.info(req.session); +// console.info(req.session); if (user._id) { req.session.user = user._id; } @@ -37,7 +47,7 @@ function fillSession (req, user, roles, cb) { // Save found user into DB, if not already exists function saveFoundToDB(found, cb) { - console.info(found); +// console.info(found); Users.findById(found.user) .exec(function(err, result){ if (err) { @@ -52,15 +62,15 @@ function saveFoundToDB(found, cb) { mail: found.mail, type: found.type, gender: found.gender, -// abos: '', -// bookmarks: '', - roles: 'user', + abos: '', + bookmarks: '', + roles: getUserRole(found), }, function(err, done) { if (err) { console.error("User creation: Failed"); console.error(err); } else { - console.info("New User created!"); + console.info("User created: "+ found.user); } if (done == null) { console.error("Can not create user."); @@ -158,7 +168,7 @@ const authorization = { console.error(err); } }); - console.info(req.session); +// console.info(req.session); return res.json ({}); }); },