Skip to content

Commit

Permalink
Merge pull request #359 from PermanentOrg/PER-8903-pass-group-instead…
Browse files Browse the repository at this point in the history
…-of-family
  • Loading branch information
crisnicandrei authored Mar 11, 2024
2 parents cc3cedf + 4e36867 commit 456fbf7
Show file tree
Hide file tree
Showing 14 changed files with 645 additions and 288 deletions.
102 changes: 67 additions & 35 deletions src/app/core/components/all-archives/all-archives.component.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,25 @@
import { Component, OnInit, AfterViewInit, QueryList, ViewChildren, Optional, OnDestroy, ViewChild } from '@angular/core';
import {
Component,
OnInit,
AfterViewInit,
QueryList,
ViewChildren,
Optional,
OnDestroy,
ViewChild,
} from '@angular/core';
import { ActivatedRoute, Router } from '@angular/router';
import { Validators } from '@angular/forms';

import { remove, orderBy, partition } from 'lodash';
import { Deferred } from '@root/vendor/deferred';

import { AccountService } from '@shared/services/account/account.service';
import { PromptService, PromptButton, PromptField } from '@shared/services/prompt/prompt.service';
import {
PromptService,
PromptButton,
PromptField,
} from '@shared/services/prompt/prompt.service';
import { MessageService } from '@shared/services/message/message.service';

import { ArchiveVO, FolderVO } from '@root/app/models';
Expand All @@ -22,7 +35,7 @@ import { CdkPortal } from '@angular/cdk/portal';
@Component({
selector: 'pr-all-archives',
templateUrl: './all-archives.component.html',
styleUrls: ['./all-archives.component.scss']
styleUrls: ['./all-archives.component.scss'],
})
export class AllArchivesComponent implements OnInit, AfterViewInit, OnDestroy {
public currentArchive: ArchiveVO;
Expand All @@ -42,28 +55,36 @@ export class AllArchivesComponent implements OnInit, AfterViewInit, OnDestroy {
private router: Router,
@Optional() private portalService: SidebarActionPortalService
) {

this.data.setCurrentFolder(new FolderVO({
displayName: 'Archives',
pathAsText: ['Archives'],
type: 'page'
}));
this.data.setCurrentFolder(
new FolderVO({
displayName: 'Archives',
pathAsText: ['Archives'],
type: 'page',
})
);
this.currentArchive = accountService.getArchive();

const archivesData = this.route.snapshot.data['archives'] || [];
const archives = orderBy(archivesData.map((archiveData) => {
return new ArchiveVO(archiveData);
}), 'fullName');
const currentArchiveFetched = remove(archives, { archiveId: this.currentArchive.archiveId })[0] as ArchiveVO;
const archives = orderBy(
archivesData.map((archiveData) => {
return new ArchiveVO(archiveData);
}),
'fullName'
);
const currentArchiveFetched = remove(archives, {
archiveId: this.currentArchive.archiveId,
})[0] as ArchiveVO;

this.currentArchive.update(currentArchiveFetched);
this.accountService.setArchive(this.currentArchive);

[ this.pendingArchives, this.archives ] = partition(archives as ArchiveVO[], a => a.isPending());
[this.pendingArchives, this.archives] = partition(
archives as ArchiveVO[],
(a) => a.isPending()
);
}

ngOnInit() {
}
ngOnInit() {}

ngAfterViewInit() {
if (this.portalService) {
Expand All @@ -83,25 +104,33 @@ export class AllArchivesComponent implements OnInit, AfterViewInit, OnDestroy {
const buttons: PromptButton[] = [
{
buttonName: 'switch',
buttonText: archive.isPending() ? 'Accept and switch archive' : 'Switch archive'
buttonText: archive.isPending()
? 'Accept and switch archive'
: 'Switch archive',
},
{
buttonName: 'cancel',
buttonText: 'Cancel',
class: 'btn-secondary'
}
class: 'btn-secondary',
},
];

let message = `Switch to The ${archive.fullName} Archive?`;

if (archive.isPending()) {
message = `You have been invited to collaborate on the ${archive.fullName} archive. Accept ${this.prConstants.translate(archive.accessRole)} access and switch?`;
message = `You have been invited to collaborate on the ${
archive.fullName
} archive. Accept ${this.prConstants.translate(
archive.accessRole
)} access and switch?`;
}

this.prompt.promptButtons(buttons, message, deferred.promise)
this.prompt
.promptButtons(buttons, message, deferred.promise)
.then((result) => {
if (result === 'switch') {
let acceptIfNeeded: Promise<ArchiveResponse | any> = Promise.resolve();
let acceptIfNeeded: Promise<ArchiveResponse | any> =
Promise.resolve();

if (archive.isPending()) {
acceptIfNeeded = this.api.archive.accept(archive);
Expand Down Expand Up @@ -160,9 +189,7 @@ export class AllArchivesComponent implements OnInit, AfterViewInit, OnDestroy {
}
}

async onRemoveClick(archive: ArchiveVO) {

}
async onRemoveClick(archive: ArchiveVO) {}

onCreateArchiveClick() {
const deferred = new Deferred();
Expand All @@ -175,9 +202,9 @@ export class AllArchivesComponent implements OnInit, AfterViewInit, OnDestroy {
autocapitalize: 'off',
autocorrect: 'off',
autocomplete: 'off',
spellcheck: 'off'
spellcheck: 'off',
},
validators: [Validators.required]
validators: [Validators.required],
},
{
fieldName: 'type',
Expand All @@ -187,22 +214,27 @@ export class AllArchivesComponent implements OnInit, AfterViewInit, OnDestroy {
selectOptions: [
{
text: 'Person',
value: 'type.archive.person'
value: 'type.archive.person',
},
{
text: 'Group',
value: 'type.archive.group',
},
{
text: 'Family',
value: 'type.archive.family'
text: 'Group',
value: 'type.archive.family',
},
{
text: 'Organization',
value: 'type.archive.organization'
}
]
value: 'type.archive.organization',
},
],
},
RELATIONSHIP_FIELD
RELATIONSHIP_FIELD,
];

this.prompt.prompt(fields, 'Create new archive', deferred.promise, 'Create archive')
this.prompt
.prompt(fields, 'Create new archive', deferred.promise, 'Create archive')
.then((value) => {
return this.api.archive.create(new ArchiveVO(value));
})
Expand Down
113 changes: 70 additions & 43 deletions src/app/core/components/archive-switcher/archive-switcher.component.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
import { Component, OnInit, AfterViewInit, QueryList, ViewChildren } from '@angular/core';
import {
Component,
OnInit,
AfterViewInit,
QueryList,
ViewChildren,
} from '@angular/core';
import { ActivatedRoute, Router } from '@angular/router';
import { Validators } from '@angular/forms';

Expand All @@ -7,7 +13,11 @@ import { Deferred } from '@root/vendor/deferred';
import { gsap } from 'gsap';

import { AccountService } from '@shared/services/account/account.service';
import { PromptService, PromptButton, PromptField } from '@shared/services/prompt/prompt.service';
import {
PromptService,
PromptButton,
PromptField,
} from '@shared/services/prompt/prompt.service';
import { MessageService } from '@shared/services/message/message.service';

import { ArchiveVO, FolderVO } from '@root/app/models';
Expand All @@ -22,7 +32,7 @@ import { DataService } from '@shared/services/data/data.service';
@Component({
selector: 'pr-archive-switcher',
templateUrl: './archive-switcher.component.html',
styleUrls: ['./archive-switcher.component.scss']
styleUrls: ['./archive-switcher.component.scss'],
})
export class ArchiveSwitcherComponent implements OnInit, AfterViewInit {
public currentArchive: ArchiveVO;
Expand All @@ -37,42 +47,46 @@ export class ArchiveSwitcherComponent implements OnInit, AfterViewInit {
private message: MessageService,
private router: Router
) {

this.data.setCurrentFolder(new FolderVO({
displayName: 'Archives',
pathAsText: ['Archives'],
type: 'page'
}));
this.data.setCurrentFolder(
new FolderVO({
displayName: 'Archives',
pathAsText: ['Archives'],
type: 'page',
})
);
this.currentArchive = accountService.getArchive();

const archivesData = this.route.snapshot.data['archives'] || [];
const archives = orderBy(archivesData.map((archiveData) => {
return new ArchiveVO(archiveData);
}), 'fullName');
const currentArchiveFetched = remove(archives, { archiveId: this.currentArchive.archiveId })[0] as ArchiveVO;
const archives = orderBy(
archivesData.map((archiveData) => {
return new ArchiveVO(archiveData);
}),
'fullName'
);
const currentArchiveFetched = remove(archives, {
archiveId: this.currentArchive.archiveId,
})[0] as ArchiveVO;

this.currentArchive.update(currentArchiveFetched);
this.accountService.setArchive(this.currentArchive);

this.archives = archives as ArchiveVO[];
}

ngOnInit() {
}
ngOnInit() {}

ngAfterViewInit() {
const targetElems = document.querySelectorAll('.archive-list pr-archive-small');
gsap.from(
targetElems,
{
duration: 0.75,
opacity: 0,
ease: 'Power4.easeOut',
stagger: {
amount: 0.5
}
}
);
const targetElems = document.querySelectorAll(
'.archive-list pr-archive-small'
);
gsap.from(targetElems, {
duration: 0.75,
opacity: 0,
ease: 'Power4.easeOut',
stagger: {
amount: 0.5,
},
});
}

archiveClick(archive: ArchiveVO) {
Expand All @@ -81,25 +95,33 @@ export class ArchiveSwitcherComponent implements OnInit, AfterViewInit {
const buttons: PromptButton[] = [
{
buttonName: 'switch',
buttonText: archive.isPending() ? 'Accept and switch archive' : 'Switch archive'
buttonText: archive.isPending()
? 'Accept and switch archive'
: 'Switch archive',
},
{
buttonName: 'cancel',
buttonText: 'Cancel',
class: 'btn-secondary'
}
class: 'btn-secondary',
},
];

let message = `Switch to The ${archive.fullName} Archive?`;

if (archive.isPending()) {
message = `You have been invited to collaborate on the ${archive.fullName} archive. Accept ${this.prConstants.translate(archive.accessRole)} access and switch?`;
message = `You have been invited to collaborate on the ${
archive.fullName
} archive. Accept ${this.prConstants.translate(
archive.accessRole
)} access and switch?`;
}

this.prompt.promptButtons(buttons, message, deferred.promise)
this.prompt
.promptButtons(buttons, message, deferred.promise)
.then((result) => {
if (result === 'switch') {
let acceptIfNeeded: Promise<ArchiveResponse | any> = Promise.resolve();
let acceptIfNeeded: Promise<ArchiveResponse | any> =
Promise.resolve();

if (archive.isPending()) {
acceptIfNeeded = this.api.archive.accept(archive);
Expand Down Expand Up @@ -134,9 +156,9 @@ export class ArchiveSwitcherComponent implements OnInit, AfterViewInit {
autocapitalize: 'off',
autocorrect: 'off',
autocomplete: 'off',
spellcheck: 'off'
spellcheck: 'off',
},
validators: [Validators.required]
validators: [Validators.required],
},
{
fieldName: 'type',
Expand All @@ -146,22 +168,27 @@ export class ArchiveSwitcherComponent implements OnInit, AfterViewInit {
selectOptions: [
{
text: 'Person',
value: 'type.archive.person'
value: 'type.archive.person',
},
{
text: 'Group',
value: 'type.archive.group',
},
{
text: 'Family',
value: 'type.archive.family'
text: 'Group',
value: 'type.archive.family',
},
{
text: 'Organization',
value: 'type.archive.organization'
}
]
value: 'type.archive.organization',
},
],
},
RELATIONSHIP_FIELD
RELATIONSHIP_FIELD,
];

this.prompt.prompt(fields, 'Create new archive', deferred.promise, 'Create archive')
this.prompt
.prompt(fields, 'Create new archive', deferred.promise, 'Create archive')
.then((value) => {
return this.api.archive.create(new ArchiveVO(value));
})
Expand Down
Loading

0 comments on commit 456fbf7

Please sign in to comment.