Skip to content

Commit

Permalink
Feature/folder (#16)
Browse files Browse the repository at this point in the history
* merge develop (#15)

* change links home page

* Project (#8)

* change links home page (#5)

* Feature/folder (#7)

* #3

* Feature/folder (#9)

* #3 update home page

* reset page home

* notification feature (#12)

* #13 Display users's avatar each project (#14)

13-display-users-avatar-project

* update comment
  • Loading branch information
quoctran18 authored Oct 3, 2017
1 parent f92c53e commit 584aba5
Show file tree
Hide file tree
Showing 6 changed files with 127 additions and 51 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
'Authentication',
'Notification',
'menuService',
'$timeout'
'$timeout',
'NotificationsService'
];
function EditArticlesAdminController(
$scope,
Expand All @@ -31,7 +32,8 @@
Authentication,
Notification,
menuService,
$timeout
$timeout,
NotificationsService
) {
var vm = this;

Expand Down Expand Up @@ -107,6 +109,15 @@
vm.editComment = editComment;
vm.editSubcomment = editSubcomment;
vm.deleteComment = deleteComment;
vm.selectionStart = 0;
vm.selectionEnd = 0;
vm.listUsers = function () {
return vm.users.filter(user => {
if (user.displayName.toLowerCase().indexOf(vm.searchUsers.toLowerCase()) !== -1) {
return user;
}
})
}
vm.keydownComment = function (event, comment) {
let value = event.target.value;
$timeout(function() {
Expand All @@ -120,21 +131,51 @@
if (event.keyCode === 8) {
if (vm.searchUsers === '') {
vm.tag.style.display = 'none';
vm.tagBox = false;
} else {
$timeout(function() {
if (event.target.selectionStart < vm.selectionStart || event.target.selectionStart >= vm.selectionEnd - 1) {
vm.tag.style.display = 'none';
vm.tagBox = false;
} else {
vm.selectionEnd -= 1;
vm.searchUsers = event.target.value.slice(vm.selectionStart, vm.selectionEnd);
}
}, 0);
}
vm.searchUsers = vm.searchUsers.slice(0, vm.searchUsers.length - 1);
} else if (event.which > 47) {
vm.searchUsers += event.key;
} else if (event.which > 47 || event.which === 32) {
$timeout(function() {
if (event.target.selectionStart <= vm.selectionStart || event.target.selectionStart > vm.selectionEnd) {
vm.tag.style.display = 'none';
vm.tagBox = false;
} else {
vm.searchUsers = event.target.value.slice(vm.selectionStart, vm.selectionEnd);
vm.selectionEnd += 1;
}
}, 0)
}
}
if (event.shiftKey && event.keyCode === 50) {
vm.searchUsers = '';
vm.tagBox = true;
let selectionStart = event.target.selectionStart;
let height, offsetLeft, place, top;
top = 0;
if (event.keyCode === 50) {
$timeout(function () {
let selectionStart = event.target.selectionStart;
let height, offsetLeft, place, top, space;
vm.searchUsers = '';
vm.tagBox = true;
vm.selectionStart = selectionStart;
vm.selectionEnd = selectionStart + 1;
top = 0;
place = event.target.value.indexOf(' ', selectionStart) !== -1
? event.target.value.indexOf(' ', selectionStart) : selectionStart + 1;
space = event.target.value.indexOf(' ', selectionStart);
if (space !== -1) {
let gt = event.target.value.indexOf('\n', selectionStart);
if (gt !== -1 && gt < space) {
place = gt;
} else {
place = space;
}
} else {
place = selectionStart + 1;
}
vm.a[0].innerText = event.target.value.slice(0, place);
vm.a[0].style.display = 'inline';
offsetLeft = vm.offsetLeft.offsetLeft;
Expand Down Expand Up @@ -244,7 +285,7 @@
for (let j = 0; j < length; j++) {
if (vm.users[j].displayName.replace(/ /gi, '') === name.slice(1)) {
if (users.indexOf(vm.users[j]._id) === -1) {
users.push(vm.users[j]._id);
users.push({ user: vm.users[j]._id, read: false});
}
value = value.replace(name, `<span style="color: #365899">${vm.users[j].displayName}</span>`);
break;
Expand All @@ -258,7 +299,7 @@
for (let j = 0; j < length; j++) {
if (vm.users[j].displayName.replace(/ /gi, '') === name.slice(1)) {
if (users.indexOf(vm.users[j]._id) === -1) {
users.push(vm.users[j]._id);
users.push({ user: vm.users[j]._id, read: false});
}
value = value.replace(name, `<span style="color: #365899">${vm.users[j].displayName}</span>`);
l = l + 36 + vm.users[j].displayName.length - name.length;
Expand Down Expand Up @@ -300,13 +341,20 @@
if (res.message) {
vm.comments = vm.comments.filter(item => item._id !== _id);
} else {
console.log(changText(res.content, 'array'));
vm.comments = vm.comments.map(item => {
if (item._id === _id) {
return res;
}
return item;
});
let notificationsService = new NotificationsService()
notificationsService.users = changText(res.content, 'array');
notificationsService.message = vm.authentication.user.displayName + ' da them ban vao 1 comment';
notificationsService.$save(res => {
if (res.message) {
console.log(res.message);
}
});
}
});
}
Expand Down Expand Up @@ -334,6 +382,14 @@
if (res.message) {
comment.subcommentList = comment.subcommentList.filter(item => item._id !== _id);
} else {
let notificationsService = new NotificationsService()
notificationsService.users = changText(res.content, 'array');
notificationsService.message = vm.authentication.user.displayName + ' da them ban vao 1 comment';
notificationsService.$save(res => {
if (res.message) {
console.log(res.message);
}
});
comment.subcommentList = comment.subcommentList.map(item => {
if (item._id === _id) {
return res;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
</nav>
</section>
<section class="content">
<div class="box">
<div class="box" style="box-shadow: none">
<div class="box-header with-border" ng-if="!vm.inline">
<h3 class="box-title" ng-bind="vm.article.title"></h3>
</div>
Expand All @@ -27,8 +27,7 @@ <h3 class="box-title" ng-bind="vm.article.title"></h3>
<label class="control-label" for="title">Title</label>
<input name="title" type="text" ng-model="vm.article.title" id="title" class="form-control" placeholder="Title" required autofocus>
</div>
<div id="editor2" contenteditable="{{vm.inline}}" style="padding: 20px"
ng-bind-html="vm.deliberatelyTrustDangerousSnippet()">
<div id="editor2" contenteditable="{{vm.inline}}" ng-bind-html="vm.deliberatelyTrustDangerousSnippet()">
</div>
</div>
</section>
Expand All @@ -50,7 +49,7 @@ <h4 ng-bind="comment.user.displayName" style="color: #365899;margin: 0"></h4>
<p ng-bind-html="vm.changText(comment.content)" style="color: #1d2129;margin: 0"></p>
<div>
<span style="color: #365899;cursor: pointer;" ng-click="vm.subcommentList(comment)">Reply </span>
<sapn ng-bind="comment.isChange ? ' &#183; ' + vm.setTime(comment.created) + ' &#183; đã chỉnh sửa ' : ' &#183; ' + vm.time(comment.created)"></span>
<sapn ng-bind="comment.isChange ? ' &#183; ' + vm.setTime(comment.created) + ' &#183; đã chỉnh sửa ' : ' &#183; ' + vm.setTime(comment.created)"></span>
</div>
<a href="#" ng-if="comment.subcomment > 0 && !comment.subcommentList" ng-click="vm.subcommentList(comment)"
ng-bind="comment.subcomment + ' câu trả lời'"></a>
Expand All @@ -72,7 +71,7 @@ <h4 ng-bind="subcomment.user.displayName" style="color: #365899;margin: 0"></h4>
<p ng-bind-html="vm.changText(subcomment.content)" style="color: #1d2129;margin: 0"></p>
<div>
<span style="color: #365899;cursor: pointer;" ng-click="vm.formSubcomment(subcomment)">Reply </span>
<sapn ng-bind="subcomment.isChange ? ' &#183; ' + vm.setTime(subcomment.created) + ' &#183; đã chỉnh sửa ' : ' &#183; ' + vm.time(subcomment.created)"></span>
<sapn ng-bind="subcomment.isChange ? ' &#183; ' + vm.setTime(subcomment.created) + ' &#183; đã chỉnh sửa ' : ' &#183; ' + vm.setTime(subcomment.created)"></span>
</div>
</div>
</div>
Expand Down Expand Up @@ -104,10 +103,10 @@ <h4 ng-bind="subcomment.user.displayName" style="color: #365899;margin: 0"></h4>
<span id="b" style="margin-left: -6px;">.</span>
</div>
</div>
<div id="tag" ng-show="(vm.users | filter: vm.searchUsers).length !== 0" class="list-group" style="width: 200px;position: absolute;z-index: 900;display: none;margin: 0">
<div id="tag" ng-show="(vm.listUsers()).length !== 0" class="list-group" style="width: 200px;position: absolute;z-index: 900;display: none;margin: 0">
<a href="#" class="list-group-item disabled" style="padding: 4px">Users</a>
<div style="overflow: auto;height: 116px">
<a href="#" class="list-group-item" ng-repeat="user in vm.users | filter: vm.searchUsers" style="padding: 8px"
<a href="#" class="list-group-item" ng-repeat="user in vm.listUsers()" style="padding: 8px"
ng-click="vm.addUserComment(user.displayName)">
<div class="media">
<div class="media-left">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ exports.invokeRolesPolicies = function () {
}, {
resources: '/api/notifications/:notificationId',
permissions: '*'
}, {
resources: '/api/notifications-read',
permissions: '*'
}]
}, {
roles: ['user'],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,11 @@
vm.project.users.splice(index, 1);
}
};
vm.check = function(userId) {
if (vm.project.users && vm.project.users.indexOf(userId) >= 0) {
vm.check = function(user) {
if (vm.project.users && vm.project.users.indexOf(user._id) >= 0) {
return true;
}
if (user.roles[0] === 'admin') {
return true;
}
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ <h1>{{vm.project._id ? 'Edit Project' : 'New Project'}}</h1>
<h3 class="">Add users</h3>
<div class="col-md-4" ng-repeat="users in vm.users">
<div class="checkbox" ng-repeat="user in users">
<label><input type="checkbox" ng-click="vm.addUser(user._id)" ng-checked="vm.check(user._id)">{{user.displayName}}</label>
<label><input type="checkbox" ng-click="vm.addUser(user._id)"
ng-disabled="user.roles[0] === 'admin'" ng-checked="vm.check(user)">{{user.displayName}}</label>
</div>
</div>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,21 @@ var path = require('path'),
exports.create = function(req, res) {
var project = new Project(req.body);
project.user = req.user._id;
project.users = [req.user._id.toString()];

project.save(function(err) {
if (err) {
return res.status(400).send({
message: errorHandler.getErrorMessage(err)
});
} else {
var users = [],
message = "You were added on " + project.name + " project",
user = project.user._id;

project.users.map( (elem) => {
users.push({user: elem})
});
addNotificationFunction.addNotification(users, message, user);
res.jsonp(project);

var users = [],
Expand Down Expand Up @@ -120,26 +127,28 @@ exports.delete = function(req, res) {
*/
exports.list = function(req, res) {
if (req.user.roles[0] === 'admin') {
Project.find().sort('-update').populate('user', 'displayName').exec(function(err, projects) {
if (err) {
return res.status(400).send({
message: errorHandler.getErrorMessage(err)
});
} else {
res.jsonp(projects);
}
});
Project.find().sort('-update').populate({ path: 'user', select: ['displayName', 'profileImageURL'] })
.exec(function(err, projects) {
if (err) {
return res.status(400).send({
message: errorHandler.getErrorMessage(err)
});
} else {
res.jsonp(projects);
}
});
} else {
var id = req.user._id.toString();
Project.find({ users: id }).sort('-update').populate('user', 'displayName').exec(function(err, projects) {
if (err) {
return res.status(400).send({
message: errorHandler.getErrorMessage(err)
});
} else {
res.jsonp(projects);
}
});
Project.find({ users: id }).sort('-update')
.populate({ path: 'user', select: ['displayName', 'profileImageURL'] }).exec(function(err, projects) {
if (err) {
return res.status(400).send({
message: errorHandler.getErrorMessage(err)
});
} else {
res.jsonp(projects);
}
});
}
};

Expand All @@ -161,11 +170,16 @@ exports.projectByID = function(req, res, next, id) {
message: 'User is not authorized'
});
}
User.find({ _id: { $in: project.users } }, { 'displayName': 1, 'profileImageURL': 1 })
.exec((err, users) => {
req.users = users;
req.project = project;
next();
});
User.find({
$or: [{
roles: "admin"
}, {
_id: project.users
}]
}, (err, users) => {
req.users = users;
req.project = project;
next();
});
});
};
};

0 comments on commit 584aba5

Please sign in to comment.