Skip to content

Commit

Permalink
Merge pull request #1698 from citizenos/master
Browse files Browse the repository at this point in the history
Master
  • Loading branch information
ilmartyrk authored Nov 27, 2024
2 parents 1641654 + a017966 commit ff31a6a
Show file tree
Hide file tree
Showing 26 changed files with 337 additions and 217 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,6 @@
</svg>
</a>
</div>
<div class="info_box" *ngIf="this.topicId">
<a (click)="app.doShowTopicNotificationSettings(this.topicId)">
<span translate="COMPONENTS.ACTIVITY_FEED.LNK_NOTIFICATION_SETTINGS"></span>
<div class="icon">
<svg width="24" height="24" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
<path d="M15 12V14L19 11.5L15 9V11H6V12H15Z" fill="#1168A8" />
</svg>
</div>
</a>
</div>
<cos-input [placeholder]="'COMPONENTS.ACTIVITY_FEED.PLACEHOLDER_FILTER' | translate"
*ngIf="!this.groupId && !this.topicId">
<div class="dropdown" [cosDropdown]>
Expand All @@ -32,7 +22,7 @@

</div>
<div class="options">
<div class="option" *ngFor="let filter of ActivityService.filters" (click)="filterActivities(filter)"
<div class="option" *ngFor="let filter of ActivityService.filters" (click)="filterActivities(filter)" (keydown)="filterActivities(filter)"
translate="COMPONENTS.ACTIVITY_FEED.FILTER_{{filter.toUpperCase()}}">
</div>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export class ActivityFeedComponent implements OnInit {
@Input() topicId?: string;
@Input() modal?: boolean;
@Input() dialogRef?: DialogRef<ActivityFeedDialogComponent>;
constructor(public ActivityService: ActivityService, private location: Location, public dialog: DialogService, public app: AppService) {
constructor(public ActivityService: ActivityService, private readonly location: Location, public dialog: DialogService, public app: AppService) {
setTimeout(() => {
this.show = true
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@

<div class="image" *ngFor="let image of newImages; index as index">
<div class="image_data">
<img [src]="image.link" />
<img [src]="image.link" [alt]="image.name"/>
<a class="name">{{image.name}}</a>
</div>
<button class="btn_small_plain icon" (click)="removeNewImage(index)">
Expand All @@ -65,7 +65,7 @@
</div>
<div class="image" *ngFor="let image of images; index as index">
<div class="image_data">
<img [src]="image.link" />
<img [src]="image.link" [alt]="image.name" />
<a class="name">{{image.name}}</a>
</div>
<button class="btn_small_plain icon" (click)="removeImage(image, index)">
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { trigger, state, style } from '@angular/animations';
import { Component, Inject, ChangeDetectorRef, OnInit } from '@angular/core';
import { Component, Inject, ChangeDetectorRef } from '@angular/core';
import { DialogService } from 'src/app/shared/dialog';
import { ActivatedRoute, Router } from '@angular/router';
import { TranslateService } from '@ngx-translate/core';
import { map, tap, Observable, take, switchMap, BehaviorSubject, Subject } from 'rxjs';
import { map, tap, Observable, take, switchMap, Subject } from 'rxjs';
import { Topic } from 'src/app/interfaces/topic';
import { AppService } from '@services/app.service';
import { ConfigService } from '@services/config.service';
Expand All @@ -23,6 +23,7 @@ import { TopicFormComponent } from 'src/app/topic/components/topic-form/topic-fo
import { BlockNavigationIfChange } from 'src/app/shared/pending-changes.guard';
import { TopicDiscussionService } from '@services/topic-discussion.service';
import { TopicSettingsDisabledDialogComponent } from 'src/app/topic/components/topic-settings-disabled-dialog/topic-settings-disabled-dialog.component';
import { TopicSettingsLockedComponent } from 'src/app/topic/components/topic-settings-locked/topic-settings-locked.component';

@Component({
selector: 'app-ideation-create',
Expand Down Expand Up @@ -97,9 +98,9 @@ export class IdeationCreateComponent extends TopicFormComponent implements Block
translate: TranslateService,
cd: ChangeDetectorRef,
@Inject(DomSanitizer) override sanitizer: DomSanitizer,
private app: AppService,
private TopicIdeationService: TopicIdeationService,
private config: ConfigService) {
private readonly app: AppService,
private readonly TopicIdeationService: TopicIdeationService,
private readonly config: ConfigService) {
super(dialog, route, router, UploadService, Notification, TopicService, GroupService, GroupMemberTopicService, TopicMemberGroupService, TopicMemberUserService, TopicInviteUserService, TopicAttachmentService, TopicDiscussionService, translate, cd, sanitizer)
this.app.darkNav = true;
this.hasUnsavedChanges = new Subject();
Expand All @@ -121,19 +122,28 @@ export class IdeationCreateComponent extends TopicFormComponent implements Block
}
return fragment
}), tap((fragment) => {
if (fragment === 'info' && !this.TopicService.canEditDescription(<Topic>this.topic)) {
if (fragment === 'ideation_system' && !this.TopicService.canEditDescription(this.topic)) {
const infoDialog = dialog.open(TopicSettingsLockedComponent);
infoDialog.afterClosed().subscribe(() => {
if (this.TopicService.canDelete(this.topic)) {
this.selectTab('settings')
} else {
this.selectTab('preview')
}
});
} else if (fragment === 'info' && !this.TopicService.canEditDescription(this.topic)) {
const infoDialog = dialog.open(TopicEditDisabledDialogComponent);
infoDialog.afterClosed().subscribe(() => {
this.selectTab('settings')
});
} else if ((fragment === 'settings' || fragment === 'ideation_system') && !this.TopicService.canDelete(<Topic>this.topic)) {
} else if ((fragment === 'settings' || fragment === 'ideation_system') && !this.TopicService.canDelete(this.topic)) {
const infoDialog = this.dialog.open(TopicSettingsDisabledDialogComponent);
infoDialog.afterClosed().subscribe(() => {
this.selectTab('info')
});
}
}));
// app.createNewTopic();

if (router.url.indexOf('/edit/') > -1) {
this.isnew = false;
}
Expand Down
35 changes: 31 additions & 4 deletions src/app/services/topic-argument.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export class TopicArgumentService extends ItemsListService {
params = {
topicId: <string | null> null,
discussionId: <string | null> null,
orderBy: <string>this.ARGUMENT_ORDER_BY.date,
orderBy: this.ARGUMENT_ORDER_BY.date,
types: <string | string[] | null>null,
sortOrder: <string | null>null,
offset: <number>0,
Expand All @@ -66,7 +66,7 @@ export class TopicArgumentService extends ItemsListService {
});
public loadArguments$ = new BehaviorSubject<void>(undefined);

constructor(private http: HttpClient, private Location: LocationService, private Auth: AuthService) {
constructor(private readonly http: HttpClient, private readonly Location: LocationService, private readonly Auth: AuthService) {
super();
this.items$ = this.loadItems();

Expand Down Expand Up @@ -173,7 +173,7 @@ export class TopicArgumentService extends ItemsListService {
return this.getArguments(params);
}

getArguments(params?: any | null) {
getArguments(params?: any) {
return this.query(params).pipe(
map((res) => {
this.count.next(res.data.count);
Expand All @@ -184,7 +184,7 @@ export class TopicArgumentService extends ItemsListService {
argument.replies.rows.forEach((reply: Argument) => this.ArgumentIds.push(reply.id))
}
})
return { rows: res.data.rows, countTotal: (res.data.count.total - res.data.count.reply) || 0 }
return { rows: res.data.rows, count: res.data.count, countTotal: (res.data.count.total - res.data.count.reply) || 0 }
}),
distinct(),
catchError(() => EMPTY)
Expand All @@ -200,4 +200,31 @@ export class TopicArgumentService extends ItemsListService {
getArgumentIdWithVersion(argumentId: string, version: number) {
return argumentId + this.ARGUMENT_VERSION_SEPARATOR + version;
};

override loadItems() {
return combineLatest([this.page$, this.params$]).pipe(
shareReplay(),
switchMap(([page, paramsValue]) => {
paramsValue.offset = (page - 1) * paramsValue.limit;
return this.getItems(paramsValue);
}),
map((res: any) => {
const params = this.params$.value;
this.countTotal$.next(res.countTotal || res.count || 0);
if (params.types?.length) {
let totalCount = 0;
let types = (!Array.isArray(params.types))? [params.types] : params.types;
console.log(res);
types.forEach((type) => totalCount += res.count[type]);
this.countTotal$.next(totalCount);
}
this.totalPages$.next(Math.ceil(this.countTotal$.value / params.limit));
this.hasMore$.next(true);
if (this.totalPages$.value === 0 || this.totalPages$.value === this.page$.value) {
this.hasMore$.next(false);
}
return Array.from<any>(res.rows);
})
);
}
}
12 changes: 6 additions & 6 deletions src/app/services/topic.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Injectable } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { ApiResponse } from 'src/app/interfaces/apiResponse';
import { LocationService } from './location.service';
import { Observable, switchMap, map, tap, of, take, BehaviorSubject, exhaustMap, shareReplay } from 'rxjs';
import { Observable, switchMap, map, of, take, BehaviorSubject, exhaustMap, shareReplay } from 'rxjs';
import { Topic } from 'src/app/interfaces/topic';
import { AuthService } from './auth.service';
import { DialogService } from 'src/app/shared/dialog';
Expand Down Expand Up @@ -67,9 +67,9 @@ export class TopicService {
};
CATEGORIES_COUNT_MAX = 3;

private loadTopic$ = new BehaviorSubject<void>(undefined);
private readonly loadTopic$ = new BehaviorSubject<void>(undefined);

constructor(private dialog: DialogService, private Location: LocationService, private http: HttpClient, private Auth: AuthService, private router: Router) { }
constructor(private readonly dialog: DialogService, private readonly Location: LocationService, private readonly http: HttpClient, private readonly Auth: AuthService, private readonly router: Router) { }

loadTopic(id: string, params?: { [key: string]: string | boolean }) {
return this.loadTopic$.pipe(
Expand Down Expand Up @@ -225,7 +225,7 @@ export class TopicService {
};

canUpdate(topic: Topic) {
return (topic && topic.permission && topic.permission.level === this.LEVELS.admin && topic.status !== this.STATUSES.closed);
return (topic?.permission && topic.permission.level === this.LEVELS.admin && topic.status !== this.STATUSES.closed);
};

changeState(topic: Topic, state: string, stateSuccess?: string) {
Expand Down Expand Up @@ -315,15 +315,15 @@ export class TopicService {
*
*/
canEditDescription(topic: Topic) {
return this.canEdit(topic) && topic.status === this.STATUSES.ideation || topic.status === this.STATUSES.inProgress || topic.status === this.STATUSES.draft;
return this.canEdit(topic) && [this.STATUSES.ideation, this.STATUSES.inProgress, this.STATUSES.draft].indexOf(topic.status) > -1;
};

canDelete(topic: Topic) {
return (topic && topic.permission?.level === this.LEVELS.admin);
};

canSendToFollowUp(topic: Topic) {
return this.canUpdate(topic) && topic.vote && topic.vote.id && topic.status !== this.STATUSES.followUp;
return this.canUpdate(topic) && topic.vote?.id && topic.status !== this.STATUSES.followUp;
};

canSendToVote(topic: Topic) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<div class="edits_wrap" [ngClass]="argument.type">
<div class="edits_header">
<div class="small_heading" translate="COMPONENTS.ARGUMENT_EDITS.HEADING"></div>
<a translate="COMPONENTS.ARGUMENT_EDITS.LNK_HIDE_EDITS" (click)="argument.showEdits = false;"></a>
<a translate (click)="hideEdits()">COMPONENTS.ARGUMENT_EDITS.LNK_HIDE_EDITS</a>
</div>
<div class="edits_content">
<div id="{{argument.id + '_v' + item.key}}" class="argument_edit" [ngClass]="'is_' + item.value['type']"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { Component, OnInit, Input } from '@angular/core';
import { TopicArgumentService } from '@services/topic-argument.service';
import { Component, Input, Output, EventEmitter } from '@angular/core';
import { NotificationService } from '@services/notification.service';
import { LocationService } from '@services/location.service';
import { Argument } from 'src/app/interfaces/argument';
Expand All @@ -10,15 +9,13 @@ import { TranslateService } from '@ngx-translate/core';
templateUrl: './argument-edits.component.html',
styleUrls: ['./argument-edits.component.scss']
})
export class ArgumentEditComponent implements OnInit {
export class ArgumentEditComponent {
@Input() argument!:Argument;
@Input() topicId!:string;
@Input() showEdits!: boolean;
@Output() showEditsChange = new EventEmitter<boolean>();

constructor(private TopicArgumentService: TopicArgumentService, private Notification: NotificationService, private Location: LocationService, private Translate: TranslateService) { }

ngOnInit(): void {
}

constructor(private readonly Notification: NotificationService, private readonly Location: LocationService, private readonly Translate: TranslateService) { }

copyArgumentLink(event: MouseEvent, version:string) {
const id = this.argument.id + '_v' + version;
Expand All @@ -37,4 +34,8 @@ export class ArgumentEditComponent implements OnInit {

this.Notification.inline(this.Translate.instant('VIEWS.TOPICS_TOPICID.ARGUMENT_LNK_COPIED'), event.pageX, event.pageY - 35);
};

hideEdits() {
this.showEditsChange.emit(false);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,10 @@
<div class="heading" translate="COMPONENTS.ARGUMENT_REPLY.HEADING"></div>
</div>
<form name="argumentReply">
<!--cos-input
placeholder="{{'COMPONENTS.ARGUMENT_REPLY.SUBJECT_CHARACTERS_LEFT' | translate:{chars: reply.subject.length, charsLeft: ARGUMENT_SUBJECT_MAXLENGTH} }}">
<input id="argument_subject" name="subject" [(ngModel)]="reply.subject"
placeholder="{{'COMPONENTS.ARGUMENT_REPLY.PLACEHOLDER_ADD_SUBJECT_TO_ARGUMENT' | translate:{chars: reply.subject.length, charsLeft: ARGUMENT_SUBJECT_MAXLENGTH} }}"
class="gray_borders" [ngClass]="{'error_input': errors?.subject}"
[attr.maxlength]="ARGUMENT_SUBJECT_MAXLENGTH" required>
<label for="argument_subject" class="error_label" *ngIf="errors?.subject">
<svg width="16" height="16" viewBox="0 0 16 16" fill="none" xmlns="http://www.w3.org/2000/svg">
<path fill-rule="evenodd" clip-rule="evenodd"
d="M8.89438 1.78863C8.52586 1.05158 7.47405 1.05158 7.10553 1.78863L0.723562 14.5526C0.391112 15.2175 0.874608 15.9998 1.61799 15.9998H14.3819C15.1253 15.9998 15.6088 15.2175 15.2763 14.5526L8.89438 1.78863ZM6.99996 6.99977C6.99996 6.44749 7.44767 5.99977 7.99996 5.99977C8.55224 5.99977 8.99996 6.44749 8.99996 6.99977V9.99977C8.99996 10.5521 8.55224 10.9998 7.99996 10.9998C7.44767 10.9998 6.99996 10.5521 6.99996 9.99977V6.99977ZM6.99996 12.9998C6.99996 12.4475 7.44767 11.9998 7.99996 11.9998C8.55224 11.9998 8.99996 12.4475 8.99996 12.9998C8.99996 13.5521 8.55224 13.9998 7.99996 13.9998C7.44767 13.9998 6.99996 13.5521 6.99996 12.9998Z"
fill="#EF4025" />
</svg>
<span translate="{{errors.subject}}"></span>
</label>
</!--cos-input-->
<textarea cosmarkdown cosmarkdowntranslatecharacterstatuskey="COMPONENTS.ARGUMENT_REPLY.CHARACTER_LIMIT"
id="argument_reply_text" [(item)]="reply.text" class="gray_borders" [ngClass]="{'error_input': errors?.text}"
placeholder="COMPONENTS.ARGUMENT_REPLY.PLACEHOLDER_WRITE_REPLY_HERE"
[limit]="ARGUMENT_TYPES_MAXLENGTH['reply']"></textarea><!--(keyup)="argumentTextLengthCheck(form, form.text)"-->
[limit]="ARGUMENT_TYPES_MAXLENGTH['reply']"></textarea>
<label for="argument_reply_text" class="error_label" *ngIf="errors?.text">
<svg width="16" height="16" viewBox="0 0 16 16" fill="none" xmlns="http://www.w3.org/2000/svg">
<path fill-rule="evenodd" clip-rule="evenodd"
Expand All @@ -43,7 +28,7 @@
</button>
</div>
<div>
<div class="btn_medium_submit bold" (click)="saveReply()" [ngClass]="{disabled: !reply.text.length}" translate="COMPONENTS.ARGUMENT_REPLY.BTN_POST_REPLY">
<div class="btn_medium_submit bold" (click)="saveReply()" [ngClass]="{disabled: !reply.text.length}" translate="COMPONENTS.ARGUMENT_REPLY.BTN_POST_REPLY" (keydown)="saveReply()">
</div>
</div>
</div>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import { NotificationService } from '@services/notification.service';
import { Component, OnInit, Input, Output, EventEmitter } from '@angular/core';
import { take, map } from 'rxjs';
import { Component, Input, Output, EventEmitter } from '@angular/core';
import { take } from 'rxjs';
import { Argument } from 'src/app/interfaces/argument';
import { AppService } from '@services/app.service';
import { AuthService } from '@services/auth.service';
import { TopicArgumentService } from '@services/topic-argument.service';
import { Router } from '@angular/router';
Expand All @@ -11,7 +10,7 @@ import { Router } from '@angular/router';
templateUrl: './argument-reply.component.html',
styleUrls: ['./argument-reply.component.scss']
})
export class ArgumentReplyComponent implements OnInit {
export class ArgumentReplyComponent {
@Input() argument!: Argument;
@Input() topicId!: string;
@Input() showReply!: boolean;
Expand All @@ -25,22 +24,10 @@ export class ArgumentReplyComponent implements OnInit {
ARGUMENT_TYPES_MAXLENGTH = this.TopicArgumentService.ARGUMENT_TYPES_MAXLENGTH;
ARGUMENT_SUBJECT_MAXLENGTH = this.TopicArgumentService.ARGUMENT_SUBJECT_MAXLENGTH;
errors = <any>null;
constructor(public AuthService: AuthService, private TopicArgumentService: TopicArgumentService, private Notification: NotificationService, private router: Router) {
this.AuthService.loggedIn$.pipe(
map((isLoggedIn) => {
if (!isLoggedIn) {
constructor(public AuthService: AuthService, private readonly TopicArgumentService: TopicArgumentService, private readonly Notification: NotificationService, private readonly router: Router) {

}
}))
}

ngOnInit(): void {
}

/* argumentTextLengthCheck(form, form.text) {
}*/

saveReply() {
const reply = {
parentId: this.argument.id,
Expand All @@ -62,34 +49,13 @@ export class ArgumentReplyComponent implements OnInit {
.save(reply)
.pipe(take(1))
.subscribe((reply) => {
/* console.log(reply);
console.log(this.argument);
this.argument.showReplies = true;
this.showReply = false;
if(!this.argument.replies.rows) this.argument.replies.rows = [];
this.argument.replies.rows.push(reply);*/
this.TopicArgumentService.reset();
this.router.navigate(['/', 'topics', this.topicId], {queryParams: {argumentId: reply.id+"_v0"}});
/*console.log(this.argument)
this.TopicArgumentService.items$.pipe(take(1)).subscribe((rows) => {
console.log('ARGUMENTS', rows);
rows.forEach((arg) => {
if (arg.id === this.argument.id) arg.showReplies = true;
if (!arg.showReplies) {
arg.replies.rows.forEach((reply: Argument) => {
arg.showReplies = true;
if (reply.id === this.argument.id) reply.showReplies = true;
});
}
})
})*/
this.TopicArgumentService.reloadArguments();
this.router.navigate(['/', 'topics', this.topicId], { queryParams: { argumentId: reply.id + "_v0" } });
});
/* function (res) {
this.form.errors = res.data.errors;
}*/

};

close () {
close() {
this.showReplyChange.emit(false);
}
}
Loading

0 comments on commit ff31a6a

Please sign in to comment.