@sneat/space-services 0.1.3 → 0.1.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/esm2022/index.js +8 -0
- package/esm2022/index.js.map +1 -0
- package/esm2022/lib/components/with-space-input.directive.js +37 -0
- package/esm2022/lib/components/with-space-input.directive.js.map +1 -0
- package/esm2022/lib/services/space-context.service.js +26 -0
- package/esm2022/lib/services/space-context.service.js.map +1 -0
- package/esm2022/lib/services/space-item.service.js +132 -0
- package/esm2022/lib/services/space-item.service.js.map +1 -0
- package/esm2022/lib/services/space-module.service.js +35 -0
- package/esm2022/lib/services/space-module.service.js.map +1 -0
- package/esm2022/lib/services/space-nav.service.js +97 -0
- package/esm2022/lib/services/space-nav.service.js.map +1 -0
- package/esm2022/lib/services/space-service.module.js +15 -0
- package/esm2022/lib/services/space-service.module.js.map +1 -0
- package/esm2022/lib/services/space.service.js +209 -0
- package/esm2022/lib/services/space.service.js.map +1 -0
- package/esm2022/sneat-space-services.js +5 -0
- package/esm2022/sneat-space-services.js.map +1 -0
- package/{src/index.ts → index.d.ts} +0 -1
- package/lib/components/with-space-input.directive.d.ts +20 -0
- package/lib/services/space-context.service.d.ts +9 -0
- package/lib/services/space-item.service.d.ts +43 -0
- package/lib/services/space-module.service.d.ts +10 -0
- package/lib/services/space-nav.service.d.ts +32 -0
- package/lib/services/space-service.module.d.ts +6 -0
- package/lib/services/space.service.d.ts +33 -0
- package/package.json +14 -2
- package/sneat-space-services.d.ts +5 -0
- package/eslint.config.js +0 -7
- package/ng-package.json +0 -7
- package/project.json +0 -38
- package/src/lib/components/with-space-input.directive.spec.ts +0 -41
- package/src/lib/components/with-space-input.directive.ts +0 -40
- package/src/lib/services/space-context.service.spec.ts +0 -16
- package/src/lib/services/space-context.service.ts +0 -45
- package/src/lib/services/space-item.service.spec.ts +0 -179
- package/src/lib/services/space-item.service.ts +0 -308
- package/src/lib/services/space-module.service.spec.ts +0 -48
- package/src/lib/services/space-module.service.ts +0 -69
- package/src/lib/services/space-nav-service.service.spec.ts +0 -32
- package/src/lib/services/space-nav.service.ts +0 -175
- package/src/lib/services/space-service.module.spec.ts +0 -46
- package/src/lib/services/space-service.module.ts +0 -7
- package/src/lib/services/space.service.spec.ts +0 -44
- package/src/lib/services/space.service.ts +0 -291
- package/src/test-setup.ts +0 -3
- package/tsconfig.json +0 -13
- package/tsconfig.lib.json +0 -19
- package/tsconfig.lib.prod.json +0 -7
- package/tsconfig.spec.json +0 -31
- package/vite.config.mts +0 -10
|
@@ -1,175 +0,0 @@
|
|
|
1
|
-
import { Injectable, inject } from '@angular/core';
|
|
2
|
-
import { Params } from '@angular/router';
|
|
3
|
-
import { NavController } from '@ionic/angular';
|
|
4
|
-
import { AnalyticsService, IAnalyticsService, IIdAndBrief, ISpaceRef } from '@sneat/core';
|
|
5
|
-
import { IMemberBrief } from '@sneat/contactus-core';
|
|
6
|
-
|
|
7
|
-
type NavigationOptions = NonNullable<
|
|
8
|
-
Parameters<NavController['navigateRoot']>[1]
|
|
9
|
-
>;
|
|
10
|
-
import { IRecord } from '@sneat/data';
|
|
11
|
-
import { ISpaceDbo } from '@sneat/dto';
|
|
12
|
-
import { ErrorLogger, IErrorLogger } from '@sneat/core';
|
|
13
|
-
import { ISpaceContext } from '@sneat/space-models';
|
|
14
|
-
|
|
15
|
-
export type ScrumPageTab = 'team' | 'my' | 'risks' | 'qna';
|
|
16
|
-
|
|
17
|
-
@Injectable({
|
|
18
|
-
providedIn: 'root',
|
|
19
|
-
})
|
|
20
|
-
export class SpaceNavService {
|
|
21
|
-
private readonly errorLogger = inject<IErrorLogger>(ErrorLogger);
|
|
22
|
-
private readonly navController = inject(NavController);
|
|
23
|
-
private readonly analyticsService =
|
|
24
|
-
inject<IAnalyticsService>(AnalyticsService);
|
|
25
|
-
|
|
26
|
-
public navigateToSpaces(animationDirection?: 'forward' | 'back'): void {
|
|
27
|
-
this.analyticsService.logEvent('navigateToTeams');
|
|
28
|
-
this.navController
|
|
29
|
-
.navigateRoot('spaces', { animationDirection })
|
|
30
|
-
.catch((err) =>
|
|
31
|
-
this.errorLogger.logError(err, 'Failed to navigate to teams page'),
|
|
32
|
-
);
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
public navigateToLogin(options?: {
|
|
36
|
-
returnTo?: string;
|
|
37
|
-
queryParams?: Params;
|
|
38
|
-
// fragment?: string;
|
|
39
|
-
}): void {
|
|
40
|
-
|
|
41
|
-
// Do not log `returnTo` as it might holds sensitive info
|
|
42
|
-
this.analyticsService.logEvent('navigateToLogin');
|
|
43
|
-
|
|
44
|
-
const navOptions: NavigationOptions = {
|
|
45
|
-
queryParams: options?.queryParams,
|
|
46
|
-
animationDirection: 'back',
|
|
47
|
-
};
|
|
48
|
-
if (options?.returnTo) {
|
|
49
|
-
navOptions.fragment = options.returnTo;
|
|
50
|
-
}
|
|
51
|
-
this.navController
|
|
52
|
-
.navigateRoot('login', navOptions)
|
|
53
|
-
.catch((err) =>
|
|
54
|
-
this.errorLogger.logError(err, 'Failed to navigate to login page'),
|
|
55
|
-
);
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
public navigateToUserProfile(): void {
|
|
59
|
-
this.analyticsService.logEvent('navigateToUserProfile');
|
|
60
|
-
this.navController
|
|
61
|
-
.navigateRoot('user-profile')
|
|
62
|
-
.catch((err) =>
|
|
63
|
-
this.errorLogger.logError(err, 'Failed to naviage to user profile'),
|
|
64
|
-
);
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
public navigateToSpace(
|
|
68
|
-
space: ISpaceContext,
|
|
69
|
-
animationDirection?: 'forward' | 'back',
|
|
70
|
-
): Promise<boolean> {
|
|
71
|
-
this.analyticsService.logEvent('navigateToSpace', { spaceID: space.id });
|
|
72
|
-
const url = `space/${space.type || space.brief?.type}/${space.id}`;
|
|
73
|
-
return new Promise<boolean>((resolve, reject) => {
|
|
74
|
-
this.navController
|
|
75
|
-
.navigateRoot(url, {
|
|
76
|
-
state: { space },
|
|
77
|
-
animationDirection,
|
|
78
|
-
})
|
|
79
|
-
.then(resolve)
|
|
80
|
-
.catch((err) => {
|
|
81
|
-
this.errorLogger.logError(
|
|
82
|
-
err,
|
|
83
|
-
'Failed to navigate to team overview page with URL: ' + url,
|
|
84
|
-
);
|
|
85
|
-
reject(err);
|
|
86
|
-
});
|
|
87
|
-
});
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
public navigateToMember(
|
|
91
|
-
space: ISpaceContext,
|
|
92
|
-
memberInfo: IIdAndBrief<IMemberBrief>,
|
|
93
|
-
): void {
|
|
94
|
-
const id = `${space.id}:${memberInfo.id}`;
|
|
95
|
-
this.navForward(
|
|
96
|
-
this.navController,
|
|
97
|
-
'member',
|
|
98
|
-
{
|
|
99
|
-
queryParams: { id },
|
|
100
|
-
state: { space, memberInfo },
|
|
101
|
-
},
|
|
102
|
-
);
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
public navigateToAddMetric = (
|
|
106
|
-
navController: NavController,
|
|
107
|
-
team: IRecord<ISpaceDbo>,
|
|
108
|
-
): void =>
|
|
109
|
-
this.navToSpacePage(
|
|
110
|
-
navController,
|
|
111
|
-
team,
|
|
112
|
-
'add-metric',
|
|
113
|
-
'navigateToAddMetric',
|
|
114
|
-
);
|
|
115
|
-
|
|
116
|
-
public navigateBackToSpacePage(
|
|
117
|
-
space: ISpaceContext,
|
|
118
|
-
page: string,
|
|
119
|
-
navOptions: NavigationOptions = {},
|
|
120
|
-
): Promise<boolean> {
|
|
121
|
-
navOptions.animationDirection = 'back';
|
|
122
|
-
return this.navigateToSpacePage(space, page, navOptions);
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
public navigateForwardToSpacePage(
|
|
126
|
-
space: ISpaceContext,
|
|
127
|
-
page: string,
|
|
128
|
-
navOptions: NavigationOptions = {},
|
|
129
|
-
): Promise<boolean> {
|
|
130
|
-
navOptions.animationDirection = 'forward';
|
|
131
|
-
return this.navigateToSpacePage(space, page, navOptions);
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
private navigateToSpacePage(
|
|
135
|
-
space: ISpaceContext,
|
|
136
|
-
page: string,
|
|
137
|
-
navOptions: NavigationOptions,
|
|
138
|
-
): Promise<boolean> {
|
|
139
|
-
const url = `space/${space?.type}/${space?.id}/${page}`;
|
|
140
|
-
const state = navOptions.state || {};
|
|
141
|
-
navOptions = { ...navOptions, state: { space, ...state } };
|
|
142
|
-
return this.navController.navigateForward(url, navOptions);
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
private navForward(
|
|
146
|
-
navController: NavController,
|
|
147
|
-
url: string,
|
|
148
|
-
navOptions: NavigationOptions,
|
|
149
|
-
// _analyticsEvent: { name: string; params?: Record<string, unknown> },
|
|
150
|
-
): void {
|
|
151
|
-
navController = navController || this.navController;
|
|
152
|
-
// this.analyticsService.logEvent(analyticsEvent.name, analyticsEvent.params);
|
|
153
|
-
navController
|
|
154
|
-
.navigateForward(url, navOptions)
|
|
155
|
-
.catch((err) =>
|
|
156
|
-
this.errorLogger.logError(err, 'Failed to navigate to: ' + url),
|
|
157
|
-
);
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
private navToSpacePage = (
|
|
161
|
-
navController: NavController,
|
|
162
|
-
space: ISpaceRef,
|
|
163
|
-
url: string,
|
|
164
|
-
eventName: string,
|
|
165
|
-
params?: Record<string, unknown>,
|
|
166
|
-
): void => {
|
|
167
|
-
params = { ...params, space: space.id };
|
|
168
|
-
this.analyticsService.logEvent(eventName, params);
|
|
169
|
-
this.navForward(
|
|
170
|
-
navController,
|
|
171
|
-
url,
|
|
172
|
-
{ queryParams: params, state: { space } },
|
|
173
|
-
);
|
|
174
|
-
};
|
|
175
|
-
}
|
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
import { TestBed } from '@angular/core/testing';
|
|
2
|
-
import { Firestore } from '@angular/fire/firestore';
|
|
3
|
-
import { SneatApiService } from '@sneat/api';
|
|
4
|
-
import { SneatAuthStateService, SneatUserService } from '@sneat/auth-core';
|
|
5
|
-
import { ErrorLogger } from '@sneat/core';
|
|
6
|
-
import { of } from 'rxjs';
|
|
7
|
-
import { SpaceServiceModule } from './space-service.module';
|
|
8
|
-
import { SpaceService } from './space.service';
|
|
9
|
-
|
|
10
|
-
describe('SpaceServiceModule', () => {
|
|
11
|
-
beforeEach(() => {
|
|
12
|
-
TestBed.configureTestingModule({
|
|
13
|
-
imports: [SpaceServiceModule],
|
|
14
|
-
providers: [
|
|
15
|
-
{
|
|
16
|
-
provide: ErrorLogger,
|
|
17
|
-
useValue: { logError: vi.fn(), logErrorHandler: () => vi.fn() },
|
|
18
|
-
},
|
|
19
|
-
{
|
|
20
|
-
provide: Firestore,
|
|
21
|
-
useValue: { type: 'Firestore', toJSON: () => ({}) },
|
|
22
|
-
},
|
|
23
|
-
{
|
|
24
|
-
provide: SneatUserService,
|
|
25
|
-
useValue: { userState: of({ record: undefined }) },
|
|
26
|
-
},
|
|
27
|
-
{
|
|
28
|
-
provide: SneatApiService,
|
|
29
|
-
useValue: { post: vi.fn(), get: vi.fn() },
|
|
30
|
-
},
|
|
31
|
-
{
|
|
32
|
-
provide: SneatAuthStateService,
|
|
33
|
-
useValue: {
|
|
34
|
-
authStatus: of('notAuthenticated'),
|
|
35
|
-
authState: of({ status: 'notAuthenticated' }),
|
|
36
|
-
},
|
|
37
|
-
},
|
|
38
|
-
],
|
|
39
|
-
});
|
|
40
|
-
});
|
|
41
|
-
|
|
42
|
-
it('should provide SpaceService', () => {
|
|
43
|
-
const service = TestBed.inject(SpaceService);
|
|
44
|
-
expect(service).toBeTruthy();
|
|
45
|
-
});
|
|
46
|
-
});
|
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
import { TestBed } from '@angular/core/testing';
|
|
2
|
-
import { Firestore } from '@angular/fire/firestore';
|
|
3
|
-
import { SneatApiService } from '@sneat/api';
|
|
4
|
-
import { SneatAuthStateService, SneatUserService } from '@sneat/auth-core';
|
|
5
|
-
import { ErrorLogger } from '@sneat/core';
|
|
6
|
-
import { of } from 'rxjs';
|
|
7
|
-
import { SpaceService } from './space.service';
|
|
8
|
-
|
|
9
|
-
describe('SpaceService', () => {
|
|
10
|
-
beforeEach(() => {
|
|
11
|
-
TestBed.configureTestingModule({
|
|
12
|
-
providers: [
|
|
13
|
-
SpaceService,
|
|
14
|
-
{
|
|
15
|
-
provide: ErrorLogger,
|
|
16
|
-
useValue: { logError: vi.fn(), logErrorHandler: () => vi.fn() },
|
|
17
|
-
},
|
|
18
|
-
{
|
|
19
|
-
provide: Firestore,
|
|
20
|
-
useValue: { type: 'Firestore', toJSON: () => ({}) },
|
|
21
|
-
},
|
|
22
|
-
{
|
|
23
|
-
provide: SneatUserService,
|
|
24
|
-
useValue: { userState: of({ record: undefined }) },
|
|
25
|
-
},
|
|
26
|
-
{
|
|
27
|
-
provide: SneatApiService,
|
|
28
|
-
useValue: { post: vi.fn(), get: vi.fn() },
|
|
29
|
-
},
|
|
30
|
-
{
|
|
31
|
-
provide: SneatAuthStateService,
|
|
32
|
-
useValue: {
|
|
33
|
-
authStatus: of('notAuthenticated'),
|
|
34
|
-
authState: of({ status: 'notAuthenticated' }),
|
|
35
|
-
},
|
|
36
|
-
},
|
|
37
|
-
],
|
|
38
|
-
});
|
|
39
|
-
});
|
|
40
|
-
|
|
41
|
-
it('should be created', () => {
|
|
42
|
-
expect(TestBed.inject(SpaceService)).toBeTruthy();
|
|
43
|
-
});
|
|
44
|
-
});
|
|
@@ -1,291 +0,0 @@
|
|
|
1
|
-
import { HttpParams } from '@angular/common/http';
|
|
2
|
-
import {
|
|
3
|
-
Injectable,
|
|
4
|
-
Injector,
|
|
5
|
-
inject,
|
|
6
|
-
runInInjectionContext,
|
|
7
|
-
} from '@angular/core';
|
|
8
|
-
import {
|
|
9
|
-
Firestore as AngularFirestore,
|
|
10
|
-
CollectionReference,
|
|
11
|
-
collection,
|
|
12
|
-
} from '@angular/fire/firestore';
|
|
13
|
-
import { SneatApiService, SneatFirestoreService } from '@sneat/api';
|
|
14
|
-
import {
|
|
15
|
-
AuthStatus,
|
|
16
|
-
AuthStatuses,
|
|
17
|
-
SneatAuthStateService,
|
|
18
|
-
} from '@sneat/auth-core';
|
|
19
|
-
import { IUserSpaceBrief } from '@sneat/auth-models';
|
|
20
|
-
import { IIdAndBrief } from '@sneat/core';
|
|
21
|
-
import { IRecord } from '@sneat/data';
|
|
22
|
-
import { ISpaceBrief, ISpaceDbo, ISpaceMetric } from '@sneat/dto';
|
|
23
|
-
import { ErrorLogger, IErrorLogger } from '@sneat/core';
|
|
24
|
-
import {
|
|
25
|
-
ICreateSpaceRequest,
|
|
26
|
-
ICreateSpaceResponse,
|
|
27
|
-
ILeaveSpaceRequest,
|
|
28
|
-
ISpaceContext,
|
|
29
|
-
IUpdateRelatedRequest,
|
|
30
|
-
zipMapBriefsWithIDs,
|
|
31
|
-
} from '@sneat/space-models';
|
|
32
|
-
import { ISneatUserState, SneatUserService } from '@sneat/auth-core';
|
|
33
|
-
import {
|
|
34
|
-
BehaviorSubject,
|
|
35
|
-
Observable,
|
|
36
|
-
Subject,
|
|
37
|
-
Subscription,
|
|
38
|
-
throwError,
|
|
39
|
-
} from 'rxjs';
|
|
40
|
-
import { filter, first, map, tap } from 'rxjs/operators';
|
|
41
|
-
|
|
42
|
-
const spaceBriefFromUserSpaceInfo = (v: IUserSpaceBrief): ISpaceBrief => ({
|
|
43
|
-
...v,
|
|
44
|
-
type: v.type,
|
|
45
|
-
});
|
|
46
|
-
|
|
47
|
-
// export class CachedDataService<Brief, Dbo extends Brief> {
|
|
48
|
-
// constructor(
|
|
49
|
-
// private readonly db: AngularFirestore,
|
|
50
|
-
// ) {
|
|
51
|
-
// }
|
|
52
|
-
//
|
|
53
|
-
// // watchRecord()
|
|
54
|
-
// }
|
|
55
|
-
|
|
56
|
-
@Injectable()
|
|
57
|
-
export class SpaceService {
|
|
58
|
-
readonly sneatAuthStateService = inject(SneatAuthStateService);
|
|
59
|
-
private readonly errorLogger = inject<IErrorLogger>(ErrorLogger);
|
|
60
|
-
private readonly afs = inject(AngularFirestore);
|
|
61
|
-
private readonly userService = inject(SneatUserService);
|
|
62
|
-
private readonly sneatApiService = inject(SneatApiService);
|
|
63
|
-
|
|
64
|
-
private userID?: string;
|
|
65
|
-
|
|
66
|
-
private currentUserSpaces?: Record<string, IUserSpaceBrief>;
|
|
67
|
-
|
|
68
|
-
private spaces$: Record<string, BehaviorSubject<ISpaceContext | undefined>> =
|
|
69
|
-
{};
|
|
70
|
-
private subscriptions: Subscription[] = [];
|
|
71
|
-
|
|
72
|
-
private readonly sfs: SneatFirestoreService<ISpaceBrief, ISpaceDbo>;
|
|
73
|
-
|
|
74
|
-
private readonly injector = inject(Injector);
|
|
75
|
-
|
|
76
|
-
constructor() {
|
|
77
|
-
const sneatAuthStateService = this.sneatAuthStateService;
|
|
78
|
-
|
|
79
|
-
// console.log('SpaceService.constructor()');
|
|
80
|
-
this.sfs = new SneatFirestoreService<ISpaceBrief, ISpaceDbo>(
|
|
81
|
-
this.injector,
|
|
82
|
-
(id: string, dto: ISpaceDbo) => ({
|
|
83
|
-
id,
|
|
84
|
-
...dto,
|
|
85
|
-
}),
|
|
86
|
-
);
|
|
87
|
-
const onAuthStatusChanged = (status: AuthStatus): void => {
|
|
88
|
-
if (status === 'notAuthenticated') {
|
|
89
|
-
this.unsubscribe('signed out');
|
|
90
|
-
}
|
|
91
|
-
};
|
|
92
|
-
sneatAuthStateService.authStatus.subscribe(onAuthStatusChanged);
|
|
93
|
-
|
|
94
|
-
// We are intentionally not un-subscribing from user record updates. TODO: why?
|
|
95
|
-
this.userService.userState.subscribe({
|
|
96
|
-
next: this.processUserRecordInSpaceService,
|
|
97
|
-
error: this.errorLogger.logErrorHandler('failed to load user record'),
|
|
98
|
-
});
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
private readonly processUserRecordInSpaceService = (
|
|
102
|
-
userState: ISneatUserState,
|
|
103
|
-
): void => {
|
|
104
|
-
const user = userState?.record;
|
|
105
|
-
if (!user) {
|
|
106
|
-
// this.userID = undefined;
|
|
107
|
-
if (
|
|
108
|
-
userState.status === AuthStatuses.notAuthenticated &&
|
|
109
|
-
this.subscriptions?.length
|
|
110
|
-
) {
|
|
111
|
-
this.unsubscribe(
|
|
112
|
-
'user is not authenticated and active team subscriptions',
|
|
113
|
-
);
|
|
114
|
-
}
|
|
115
|
-
return;
|
|
116
|
-
}
|
|
117
|
-
if (userState.user?.uid !== this.userID) {
|
|
118
|
-
if (this.userID) {
|
|
119
|
-
this.unsubscribe('user id changed');
|
|
120
|
-
}
|
|
121
|
-
this.userID = userState.user?.uid;
|
|
122
|
-
}
|
|
123
|
-
this.currentUserSpaces = user?.spaces;
|
|
124
|
-
|
|
125
|
-
zipMapBriefsWithIDs(user.spaces).forEach(this.subscribeForUserSpaceChanges);
|
|
126
|
-
};
|
|
127
|
-
|
|
128
|
-
public createSpace(
|
|
129
|
-
request: ICreateSpaceRequest,
|
|
130
|
-
): Observable<IRecord<ISpaceDbo>> {
|
|
131
|
-
return this.sneatApiService
|
|
132
|
-
.post<ICreateSpaceResponse>('spaces/create_space', request)
|
|
133
|
-
.pipe(map((response: ICreateSpaceResponse) => response.space));
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
// public getSpace(ref: ISpaceRef): Observable<ISpaceContext> {
|
|
137
|
-
// return this.watchSpace(ref).pipe(first());
|
|
138
|
-
// }
|
|
139
|
-
|
|
140
|
-
public watchSpace(id: string): Observable<ISpaceContext> {
|
|
141
|
-
if (!id) {
|
|
142
|
-
throw new Error('space id is a required parameter');
|
|
143
|
-
}
|
|
144
|
-
if (id === 'contacts') {
|
|
145
|
-
throw new Error('watchSpace({i}d===contacts})');
|
|
146
|
-
}
|
|
147
|
-
let subj = this.spaces$[id];
|
|
148
|
-
if (subj) {
|
|
149
|
-
return subj.asObservable().pipe(filter((s) => !!s));
|
|
150
|
-
}
|
|
151
|
-
let spaceContext: ISpaceContext | undefined = undefined;
|
|
152
|
-
if (this.currentUserSpaces) {
|
|
153
|
-
const userSpaceInfo = this.currentUserSpaces[id];
|
|
154
|
-
if (userSpaceInfo) {
|
|
155
|
-
spaceContext = {
|
|
156
|
-
id,
|
|
157
|
-
type: userSpaceInfo.type,
|
|
158
|
-
brief: spaceBriefFromUserSpaceInfo(userSpaceInfo),
|
|
159
|
-
};
|
|
160
|
-
}
|
|
161
|
-
}
|
|
162
|
-
subj = new BehaviorSubject<ISpaceContext | undefined>(spaceContext);
|
|
163
|
-
this.spaces$[id] = subj;
|
|
164
|
-
if (this.userService.currentUserID) {
|
|
165
|
-
this.subscribeForSpaceChanges(id, subj);
|
|
166
|
-
} else {
|
|
167
|
-
this.userService.userState
|
|
168
|
-
.pipe(
|
|
169
|
-
filter((v) => v.status === AuthStatuses.authenticated),
|
|
170
|
-
first(),
|
|
171
|
-
)
|
|
172
|
-
.subscribe({
|
|
173
|
-
next: () => this.subscribeForSpaceChanges(id, subj),
|
|
174
|
-
});
|
|
175
|
-
}
|
|
176
|
-
return subj.asObservable().pipe(filter((s) => !!s));
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
public onSpaceUpdated(space: ISpaceContext): void {
|
|
180
|
-
let team$ = this.spaces$[space.id];
|
|
181
|
-
if (team$) {
|
|
182
|
-
const prevTeam = team$.value;
|
|
183
|
-
space = { ...prevTeam, ...space };
|
|
184
|
-
} else {
|
|
185
|
-
this.spaces$[space.id] = team$ = new BehaviorSubject<
|
|
186
|
-
ISpaceContext | undefined
|
|
187
|
-
>(space);
|
|
188
|
-
}
|
|
189
|
-
team$.next(space);
|
|
190
|
-
}
|
|
191
|
-
|
|
192
|
-
public leaveSpace(request: ILeaveSpaceRequest): Observable<void> {
|
|
193
|
-
return this.sneatApiService.post('space/leave_space', request);
|
|
194
|
-
}
|
|
195
|
-
|
|
196
|
-
public updateRelated(request: IUpdateRelatedRequest): Observable<void> {
|
|
197
|
-
return this.sneatApiService.post('space/update_related', request);
|
|
198
|
-
}
|
|
199
|
-
|
|
200
|
-
// TODO: move to separate module
|
|
201
|
-
public deleteMetrics(space: string, metrics: string[]): Observable<void> {
|
|
202
|
-
return this.sneatApiService.post('space/remove_metrics', {
|
|
203
|
-
space,
|
|
204
|
-
metrics,
|
|
205
|
-
});
|
|
206
|
-
}
|
|
207
|
-
|
|
208
|
-
// TODO: move to separate module
|
|
209
|
-
public addMetric(space: string, metric: ISpaceMetric): Observable<void> {
|
|
210
|
-
if (!space) {
|
|
211
|
-
return throwError(() => 'space parameter is required');
|
|
212
|
-
}
|
|
213
|
-
const params = new HttpParams({ fromObject: { id: space } });
|
|
214
|
-
return this.sneatApiService.post('space/add_metric?' + params.toString(), {
|
|
215
|
-
metric,
|
|
216
|
-
});
|
|
217
|
-
}
|
|
218
|
-
|
|
219
|
-
private readonly subscribeForUserSpaceChanges = (
|
|
220
|
-
userSpaceBrief: IIdAndBrief<IUserSpaceBrief>,
|
|
221
|
-
): void => {
|
|
222
|
-
let subj = this.spaces$[userSpaceBrief.id];
|
|
223
|
-
if (subj) {
|
|
224
|
-
let space = subj.value;
|
|
225
|
-
if (space && !space?.type) {
|
|
226
|
-
space = {
|
|
227
|
-
...space,
|
|
228
|
-
type: userSpaceBrief.brief?.type,
|
|
229
|
-
brief: spaceBriefFromUserSpaceInfo(userSpaceBrief.brief),
|
|
230
|
-
};
|
|
231
|
-
subj.next(space);
|
|
232
|
-
}
|
|
233
|
-
return;
|
|
234
|
-
}
|
|
235
|
-
|
|
236
|
-
const space: ISpaceContext = {
|
|
237
|
-
id: userSpaceBrief.id,
|
|
238
|
-
type: userSpaceBrief.brief.type,
|
|
239
|
-
brief: spaceBriefFromUserSpaceInfo(userSpaceBrief.brief),
|
|
240
|
-
};
|
|
241
|
-
this.spaces$[space.id] = subj = new BehaviorSubject<
|
|
242
|
-
ISpaceContext | undefined
|
|
243
|
-
>(space);
|
|
244
|
-
this.subscribeForSpaceChanges(space.id, subj);
|
|
245
|
-
};
|
|
246
|
-
|
|
247
|
-
private subscribeForSpaceChanges(
|
|
248
|
-
id: string,
|
|
249
|
-
subj: Subject<ISpaceContext | undefined>,
|
|
250
|
-
): void {
|
|
251
|
-
if (id === 'contacts') {
|
|
252
|
-
throw new Error('subscribeForSpaceChanges(id===contacts)');
|
|
253
|
-
}
|
|
254
|
-
const spacesCollection = runInInjectionContext(
|
|
255
|
-
this.injector,
|
|
256
|
-
() => collection(this.afs, 'spaces') as CollectionReference<ISpaceDbo>,
|
|
257
|
-
);
|
|
258
|
-
const o: Observable<ISpaceContext> = this.sfs
|
|
259
|
-
.watchByID(spacesCollection, id)
|
|
260
|
-
.pipe(
|
|
261
|
-
map((team) => {
|
|
262
|
-
// const _prevTeam = this.spaces$[id].value;
|
|
263
|
-
// if (prevTeam.assets) {
|
|
264
|
-
// team = { ...team, assets: prevTeam.assets};
|
|
265
|
-
// console.log('Reusing assets from prev context');
|
|
266
|
-
// }
|
|
267
|
-
return team;
|
|
268
|
-
}),
|
|
269
|
-
tap(() => {
|
|
270
|
-
// subj.next(team);
|
|
271
|
-
}),
|
|
272
|
-
);
|
|
273
|
-
|
|
274
|
-
this.subscriptions.push(
|
|
275
|
-
o.subscribe({
|
|
276
|
-
next: (v) => subj.next(v), // Do not use as "next: subj.next" because it will be called with wrong "this" context
|
|
277
|
-
error: (err) => subj.error(err),
|
|
278
|
-
}),
|
|
279
|
-
);
|
|
280
|
-
}
|
|
281
|
-
|
|
282
|
-
private unsubscribe(_reason?: string): void {
|
|
283
|
-
try {
|
|
284
|
-
this.subscriptions.forEach((s) => s.unsubscribe());
|
|
285
|
-
this.subscriptions = [];
|
|
286
|
-
this.spaces$ = {};
|
|
287
|
-
} catch (e) {
|
|
288
|
-
this.errorLogger.logError(e, 'SpaceService failed to unsubscribe');
|
|
289
|
-
}
|
|
290
|
-
}
|
|
291
|
-
}
|
package/src/test-setup.ts
DELETED
package/tsconfig.json
DELETED
package/tsconfig.lib.json
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"extends": "../../../tsconfig.lib.base.json",
|
|
3
|
-
"exclude": [
|
|
4
|
-
"vite.config.ts",
|
|
5
|
-
"vite.config.mts",
|
|
6
|
-
"vitest.config.ts",
|
|
7
|
-
"vitest.config.mts",
|
|
8
|
-
"src/**/*.test.ts",
|
|
9
|
-
"src/**/*.spec.ts",
|
|
10
|
-
"src/**/*.test.tsx",
|
|
11
|
-
"src/**/*.spec.tsx",
|
|
12
|
-
"src/**/*.test.js",
|
|
13
|
-
"src/**/*.spec.js",
|
|
14
|
-
"src/**/*.test.jsx",
|
|
15
|
-
"src/**/*.spec.jsx",
|
|
16
|
-
"src/test-setup.ts",
|
|
17
|
-
"src/lib/testing/**/*"
|
|
18
|
-
]
|
|
19
|
-
}
|
package/tsconfig.lib.prod.json
DELETED
package/tsconfig.spec.json
DELETED
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"extends": "./tsconfig.json",
|
|
3
|
-
"compilerOptions": {
|
|
4
|
-
"outDir": "../../../dist/out-tsc",
|
|
5
|
-
"types": [
|
|
6
|
-
"vitest/globals",
|
|
7
|
-
"vitest/importMeta",
|
|
8
|
-
"vite/client",
|
|
9
|
-
"node",
|
|
10
|
-
"vitest"
|
|
11
|
-
]
|
|
12
|
-
},
|
|
13
|
-
"include": [
|
|
14
|
-
"vite.config.ts",
|
|
15
|
-
"vite.config.mts",
|
|
16
|
-
"vitest.config.ts",
|
|
17
|
-
"vitest.config.mts",
|
|
18
|
-
"src/**/*.test.ts",
|
|
19
|
-
"src/**/*.spec.ts",
|
|
20
|
-
"src/**/*.test.tsx",
|
|
21
|
-
"src/**/*.spec.tsx",
|
|
22
|
-
"src/**/*.test.js",
|
|
23
|
-
"src/**/*.spec.js",
|
|
24
|
-
"src/**/*.test.jsx",
|
|
25
|
-
"src/**/*.spec.jsx",
|
|
26
|
-
"src/**/*.d.ts"
|
|
27
|
-
],
|
|
28
|
-
"files": [
|
|
29
|
-
"src/test-setup.ts"
|
|
30
|
-
]
|
|
31
|
-
}
|
package/vite.config.mts
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
/// <reference types='vitest' />
|
|
2
|
-
import { defineConfig } from 'vitest/config';
|
|
3
|
-
import { createBaseViteConfig } from '../../../vite.config.base';
|
|
4
|
-
|
|
5
|
-
export default defineConfig(() =>
|
|
6
|
-
createBaseViteConfig({
|
|
7
|
-
dirname: __dirname,
|
|
8
|
-
name: 'space-services',
|
|
9
|
-
}),
|
|
10
|
-
);
|