Skip to content

Commit

Permalink
Modified all entities to add author class, corrected edit feature, UI…
Browse files Browse the repository at this point in the history
… adjustments for adding supervisors and contributors
  • Loading branch information
sajeeth1009 committed Nov 10, 2019
1 parent f666ae1 commit fc77409
Show file tree
Hide file tree
Showing 28 changed files with 323 additions and 61 deletions.
6 changes: 5 additions & 1 deletion srv/src/entities/label.entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,13 @@ export class Label {
@Column()
authorId: ObjectID;

constructor(projectId: ObjectID, authorId: ObjectID, name: string) {
@Column()
authorClass: string;

constructor(projectId: ObjectID, authorId: ObjectID, name: string, authorClass: string) {
this.projectId = projectId;
this.authorId = authorId;
this.name = name;
this.authorClass = authorClass;
}
}
6 changes: 5 additions & 1 deletion srv/src/entities/labelcategory.entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,14 @@ export class LabelCategory {
@Column()
labels: Label[];

constructor(projectId: ObjectID, authorId: ObjectID, name: string, labels: Label[]) {
@Column()
authorClass: string;

constructor(projectId: ObjectID, authorId: ObjectID, name: string, labels: Label[], authorClass: string) {
this.projectId = projectId;
this.authorId = authorId;
this.name = name;
this.labels = labels;
this.authorClass = authorClass;
}
}
8 changes: 6 additions & 2 deletions srv/src/entities/project.entity.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Column, Entity, ObjectIdColumn } from 'typeorm';
import { Directory } from './directory.entity';
import { ObjectID } from 'mongodb';
import { User } from './user.entity';

@Entity()
export class Project {
Expand All @@ -12,10 +13,13 @@ export class Project {
title: string;

@Column()
ownerId: ObjectID;
ownerId: User;

@Column()
memberIds: ObjectID[];
supervisorIds: User[];

@Column()
contributorIds: User[];

@Column()
description: string;
Expand Down
6 changes: 5 additions & 1 deletion srv/src/entities/segment.entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,14 @@ export class Segment {
@Column()
labelId: ObjectID;

constructor(labelId: ObjectID, authorId: ObjectID, start: number, end: number) {
@Column()
authorClass: string;

constructor(labelId: ObjectID, authorId: ObjectID, start: number, end: number, authorClass: string) {
this.labelId = labelId;
this.authorId = authorId;
this.start = start;
this.end = end;
this.authorClass = authorClass;
}
}
16 changes: 8 additions & 8 deletions srv/src/labels/labels.gateway.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,19 +62,18 @@ export class LabelsGateway {
@SubscribeMessage('addLabel')
async addLabel(socket: SocketIO.Socket, data) {
const room = LabelsGateway.getProjectRoom(socket);
return await this.labelsService.createLabel(room, data.aid, data.cid)
.then(async (value: InsertResult) => {
const id = value.identifiers[0].id;
const newLabel: Label = await this.labelsService.getLabel(id);
socket.to(room).broadcast.emit('newLabels', newLabel);
return newLabel;
return await this.labelsService.createLabel(room, data.aid, data.cid, data.authorClass)
.then(async (value: Label) => {
value['categoryId'] = data.cid;
socket.to(room).broadcast.emit('newLabels', value);
return value;
});
}

@SubscribeMessage('addLabelCategory')
async addLabelCategory(socket: SocketIO.Socket, data) {
const room = LabelsGateway.getProjectRoom(socket);
return await this.labelsService.createLabelCategory(room, data.aid)
return await this.labelsService.createLabelCategory(room, data.aid, data.authorClass)
.then(async (value: InsertResult) => {
const id = value.identifiers[0].id;
const newLabelCategory: LabelCategory = await this.labelsService.getLabelCategory(id);
Expand Down Expand Up @@ -157,9 +156,10 @@ export class LabelsGateway {
const authorId = '';
const start = data.start;
const end = data.end;
const authorClass = data.authorClass;
const hyperid = data.hyperid;
return await this.segmentService
.createSegment(labelId, authorId, start, end)
.createSegment(labelId, authorId, start, end, authorClass)
.then(() => {
return false;
}, () => {
Expand Down
17 changes: 10 additions & 7 deletions srv/src/labels/labels.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,21 @@ export class LabelsService {
private readonly labelCategoryRepository: MongoRepository<LabelCategory>) {
}

async createLabel(projectId: string, authorId: string, categoryId: string): Promise<InsertResult> {
let labelCategory = await this.labelCategoryRepository.findOne(categoryId);
const label = new Label(projectId, authorId, labelCategory.name+'_'+(labelCategory.labels.length + 1));
return await this.labelRepository.insert(label);
async createLabel(projectId: string, authorId: string, categoryId: string, authorClass: string): Promise<Label> {
let labelCategory: LabelCategory = await this.labelCategoryRepository.findOne(categoryId);
const label = new Label(projectId, authorId, labelCategory.name+'_'+(labelCategory.labels.length + 1), authorClass);
await this.labelRepository.insert(label);
labelCategory.labels.push(label);
await this.labelCategoryRepository.update(labelCategory.id.toString(), {labels: labelCategory.labels});
return await this.labelRepository.findOne(label);
}

async createLabelCategory(projectId: string, authorId: string): Promise<InsertResult> {
let label = new Label(projectId, authorId, 'LabelCategory_1');
async createLabelCategory(projectId: string, authorId: string, authorClass: string): Promise<InsertResult> {
let label = new Label(projectId, authorId, 'LabelInstance_1', authorClass);
await this.labelRepository.insert(label);
let labels: Label[] = [];
labels.push(label);
const labelCategory = new LabelCategory(projectId, authorId, 'LabelCategory', labels);
const labelCategory = new LabelCategory(projectId, authorId, 'LabelCategory', labels, authorClass);
return await this.labelCategoryRepository.insert(labelCategory);
}

Expand Down
4 changes: 2 additions & 2 deletions srv/src/labels/segment/segment.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ export class SegmentService {
private readonly segmentRepository: MongoRepository<Segment>) {
}

async createSegment(labelId: string, authorId: string, start: number, end: number) {
const segment = new Segment(labelId, authorId, start, end);
async createSegment(labelId: string, authorId: string, start: number, end: number, authorClass: string) {
const segment = new Segment(labelId, authorId, start, end, authorClass);
return await this.segmentRepository.insert(segment);
}

Expand Down
29 changes: 22 additions & 7 deletions srv/src/project/project.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import { Segment } from '../entities/segment.entity';
import { ObjectID } from 'mongodb';
import { config } from '../../config';
import { LabelCategory } from '../entities/labelcategory.entity';
import { User } from '../entities/user.entity';

interface FileUpload {
readonly fieldname: string;
Expand Down Expand Up @@ -57,9 +58,17 @@ export class ProjectController {
project.description = body.description;
project.singleMedia = body.singleMedia;
project.modified = new Date();
project.ownerId = req.user.id;
project.memberIds = [];
project.memberIds.push(project.ownerId);
project.ownerId = req.user;
project.contributorIds = [];
project.supervisorIds = [];

body.supervisorIds.map( userdetails => {
project.supervisorIds.push(userdetails);
});

body.contributorIds.map( userdetails => {
project.contributorIds.push(userdetails);
});

project.fileTree = new Directory();
project.fileTree.parent = null;
Expand All @@ -73,8 +82,8 @@ export class ProjectController {
@UseGuards(AuthGuard())
async inviteMembers(@Param('id') id, @Req() req, @Body() body) {
const project: Project = await this.projectService.findOne(id);
const members: ObjectID[] = project.memberIds;
project.memberIds = req.project.memberIds;
project.supervisorIds = req.project.supervisorIds;
project.contributorIds = req.project.contributorIds;
return await this.projectService.update(project.id.toHexString(), project);
}

Expand Down Expand Up @@ -156,11 +165,17 @@ export class ProjectController {
const project = await this.projectService.findOne(id);
let memberIds = [];
if (body) {
let members:string[] = body['memberIds'];
let members:User[] = body['contributorIds'];
for (var member of members) {
memberIds.push(ObjectID.createFromHexString(member));
}
project.contributorIds = memberIds;
memberIds = [];
members = body['supervisorIds'];
for (var member of members) {
memberIds.push(ObjectID.createFromHexString(member));
}
project.memberIds = memberIds;
project.supervisorIds = memberIds;
return await this.projectService.update(id, project);
}
}
Expand Down
2 changes: 1 addition & 1 deletion srv/src/project/project.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export class ProjectService {
const y = ObjectID.createFromHexString(userId);
const allProjects = await this.projectRepository.find();
return allProjects.filter(x => {
return x.ownerId.equals(y) || x.memberIds.find(value => y.equals(value));
return x.ownerId.id.equals(y) || x.contributorIds.find((value) => value.id == y) != null || x.supervisorIds.find((value) => value.id == y) != null;
});
//return allProjects;
}
Expand Down
6 changes: 6 additions & 0 deletions srv/src/users/users.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,12 @@ export class UsersController {
return await this.usersService.findUsersByIds(req.headers.ids.toString().split(','));
}

@Get(':username')
@UseGuards(AuthGuard())
async getUsersByUsername(@Param('username') username): Promise<UserModel[]> {
return await this.usersService.findByUsername(username);
}

private static isValidUserDto(userDto: UserRegistrationDto) {
if (userDto) {
if (userDto.username) {
Expand Down
9 changes: 8 additions & 1 deletion srv/src/users/users.service.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Injectable } from '@nestjs/common';
import { User } from '../entities/user.entity';
import { MongoRepository } from 'typeorm';
import { MongoRepository, Like } from 'typeorm';
import { InjectRepository } from '@nestjs/typeorm';
import { UserModel } from './user.model';

Expand Down Expand Up @@ -45,4 +45,11 @@ export class UsersService {
async findOneById(id: string) {
return await this.userRepository.findOne(id);
}

async findByUsername(username: string) {
const users = await this.userRepository.find();
return users.filter(x => {
return x.username.startsWith(username);
});
}
}
7 changes: 7 additions & 0 deletions web/src/app/auth/auth.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,13 @@ export class AuthService {
.pipe(catchError(this.handleError<UserModel[]>(`fetch users for ids: ${id}`)));
}

getUsersByUsername(username: string): Observable<UserModel[]> {
const headers = new HttpHeaders({'username': username});
const url = `${this.userUrl}/${username}`;
return this.http.get<UserModel[]>(url, {headers: headers})
.pipe(catchError(this.handleError<UserModel[]>(`fetch users for username: ${username}`)));
}

/**
* Handle Http operation that failed.
* Let the app continue.
Expand Down
12 changes: 12 additions & 0 deletions web/src/app/editor/current-project.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,16 @@ export class CurrentProjectService {
exportCsv(projectId: string): Observable<any> {
return this.projectsService.exportCsv(projectId);
}

findUserRole(project: ProjectModel, userId: string): string {
if(project.ownerId.id === userId) return 'owner';
let role = '';
project.contributorIds.map(value => {
if (value.id === userId) role = 'contributor';
});
project.supervisorIds.map(value => {
if (value.id === userId) role = 'supervisor';
});
return role;
}
}
20 changes: 15 additions & 5 deletions web/src/app/editor/timeline/timeline.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ export class TimelineComponent implements OnInit, AfterViewInit, OnDestroy {
const categoryLabel = document.createElement('label');
categoryLabel.innerHTML = group['category'];
categoryLabel.addEventListener('click', () => {
this.labelsService.addLabel(JSON.parse(localStorage.getItem('currentSession$'))['user']['id'],group['categoryId']);
this.labelsService.addLabel(JSON.parse(localStorage.getItem('currentSession$'))['user']['id'],group['categoryId'], this.userRole);
});

//categoryContainer.prepend(categoryInput);
Expand Down Expand Up @@ -184,6 +184,7 @@ export class TimelineComponent implements OnInit, AfterViewInit, OnDestroy {
private currentTime = 0;

private checkboxChange = new EventEmitter<{ id: IdType, checked: boolean }>();
private userRole: string;

constructor(private projectService: CurrentProjectService,
private labelsService: LabelsService,
Expand All @@ -197,6 +198,7 @@ export class TimelineComponent implements OnInit, AfterViewInit, OnDestroy {
.subscribe(project => {
if (project) {
this.project = project;
this.userRole = this.projectService.findUserRole(project, JSON.parse(localStorage.getItem('currentSession$'))['user']['id']);

/*this.labelsService.getLabels()
.then((labels: LabelModel[]) => {
Expand Down Expand Up @@ -264,7 +266,8 @@ export class TimelineComponent implements OnInit, AfterViewInit, OnDestroy {
hyperid: item.id,
group: item.group,
start: item.start,
end: item.end
end: item.end,
userRole: this.userRole
};
this.labelsService.addSegment(segment).then(() => {
console.log('segment added');
Expand Down Expand Up @@ -345,14 +348,19 @@ export class TimelineComponent implements OnInit, AfterViewInit, OnDestroy {
private observeLabels() {
this.subscription.add(this.labelsService.newLabels$().subscribe(newLabel => {
if (newLabel) {
const group = {id: newLabel.id, content: newLabel.name};
this.timelineData.addGroup(group);
let category: LabelCategoryModel = this.labelCategories.find(value => value.id == newLabel['categoryId'] );
if(category!= null) {
category.labels.push(newLabel);
const group = {id: newLabel.id, content: newLabel.name, category: category.name, categoryId: category.id};
this.timelineData.addGroup(group);
this.timelineData.sortByCategories();
}
}
}));

this.subscription.add(this.labelsService.newLabelCategories$().subscribe(newLabelCategories => {
if (newLabelCategories) {
const group = {id: newLabelCategories["labels"][0]["_id"], content: newLabelCategories["labels"][0]["name"], category: newLabelCategories.name};
const group = {id: newLabelCategories["labels"][0]["_id"], content: newLabelCategories["labels"][0]["name"], category: newLabelCategories.name, categoryId: newLabelCategories.id};
this.timelineData.addGroup(group);
this.labelCategories.push(newLabelCategories);
}
Expand All @@ -367,6 +375,7 @@ export class TimelineComponent implements OnInit, AfterViewInit, OnDestroy {
this.subscription.add(this.labelsService.removedLabelCategories$().subscribe(removed => {
if (removed) {
let removedCategory: LabelCategoryModel = this.labelCategories.find((labelCategory) => { return labelCategory.id === removed.id;});
this.timelineData.deleteGroupCategory(removedCategory.id);
removedCategory.labels.map( label => this.timelineData.removeGroup(label["_id"]));
this.labelCategories.filter(item => item !== removedCategory);
}
Expand All @@ -385,6 +394,7 @@ export class TimelineComponent implements OnInit, AfterViewInit, OnDestroy {
let category: LabelCategoryModel = this.labelCategories.find( item => item.id === changed.id);
category.name = changed.change;
category.labels.map( label => label.name = changed.change + '_' + label.name.split('_')[1]);
this.timeline.redraw();
}
})
);
Expand Down
14 changes: 14 additions & 0 deletions web/src/app/editor/timeline/timeline.data.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import * as vis from 'vis';
import { DataGroup, DataItem, DataSet, IdType } from 'vis';
import * as hyperid from 'hyperid';

import _ from "lodash";
import { Time } from './time';

export class TimelineData {
Expand Down Expand Up @@ -129,4 +131,16 @@ export class TimelineData {
}
});
}

deleteGroupCategory(categoryId: string) {
this._groups.forEach((group, id) => {
if(group['categoryId'] === categoryId) {
this.removeGroup(id.toString());
}
});
}

sortByCategories() {
console.log(this._groups);
}
}
Loading

0 comments on commit fc77409

Please sign in to comment.