Skip to content

Create core #2797

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 9 commits into
base: next
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion apps/back-office/src/app/app.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ import {
LoggerService,
CsDocsPropertiesDropdownComponent,
AcceptedValueTypesTextComponent,
CommonServicesService,
} from '@oort-front/shared';
import { CommonServicesService } from '@oort-front/core';

/**
* Root component of back-office.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,9 @@ import {
ApplicationService,
UnsubscribeComponent,
ConfirmService,
BlobType,
DownloadService,
RestService,
AsyncMonacoEditorDirective,
} from '@oort-front/shared';
import { RestService } from '@oort-front/core';
import { takeUntil } from 'rxjs/operators';
import { TranslateModule, TranslateService } from '@ngx-translate/core';
import {
Expand All @@ -31,6 +29,7 @@ import { debounceTime, distinctUntilChanged } from 'rxjs/operators';
import { DOCUMENT } from '@angular/common';
import { ResizeEvent } from 'angular-resizable-element';
import { ResizableModule } from 'angular-resizable-element';
import { DownloadService, BlobType } from '@oort-front/core';

/** Default css style example to initialize the form and editor */
const DEFAULT_STYLE = '';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import { DUPLICATE_APPLICATION } from './graphql/mutations';
import {
Application,
DuplicateApplicationMutationResponse,
SnackbarSpinnerComponent,
} from '@oort-front/shared';
import { SnackbarSpinnerComponent } from '@oort-front/core';
import { TranslateService } from '@ngx-translate/core';
import { CommonModule } from '@angular/common';
import { FormsModule, ReactiveFormsModule } from '@angular/forms';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ import {
status,
FormQueryResponse,
EditFormMutationResponse,
SnackbarSpinnerComponent,
} from '@oort-front/shared';
import { SnackbarSpinnerComponent } from '@oort-front/core';
import { SpinnerComponent } from '@oort-front/ui';
import { Observable } from 'rxjs';
import { map } from 'rxjs/operators';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import {
RestoreRecordMutationResponse,
BreadcrumbService,
ConfirmService,
DownloadService,
getCachedValues,
updateQueryUniqueValues,
} from '@oort-front/shared';
Expand All @@ -33,6 +32,7 @@ import {
} from '@oort-front/ui';
import { GraphQLError } from 'graphql';
import { ApolloQueryResult } from '@apollo/client';
import { DownloadService } from '@oort-front/core';

/** Default items per query, for pagination */
const ITEMS_PER_PAGE = 10;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import {
Form,
ConfirmService,
Resource,
DownloadService,
UnsubscribeComponent,
ResourceRecordsNodesQueryResponse,
DeleteRecordMutationResponse,
Expand All @@ -24,6 +23,7 @@ import {
} from '@oort-front/ui';
import { takeUntil } from 'rxjs';
import { GraphQLError } from 'graphql';
import { DownloadService } from '@oort-front/core';

/** Quantity of resource that will be loaded at once. */
const ITEMS_PER_PAGE = 10;
Expand Down
21 changes: 16 additions & 5 deletions apps/back-office/src/app/dashboard/pages/users/users.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import {
AddUsersMutationResponse,
ConfirmService,
DeleteUsersMutationResponse,
DownloadService,
Role,
RolesQueryResponse,
UnsubscribeComponent,
Expand All @@ -27,6 +26,7 @@ import { TranslateService } from '@ngx-translate/core';
import { takeUntil } from 'rxjs';
import { CompositeFilterDescriptor } from '@progress/kendo-data-query';
import { ApolloQueryResult } from '@apollo/client';
import { RestService, DownloadService } from '@oort-front/core';

/** Default items per page for pagination. */
const ITEMS_PER_PAGE = 10;
Expand Down Expand Up @@ -92,6 +92,7 @@ export class UsersComponent extends UnsubscribeComponent implements OnInit {
* @param confirmService Shared confirm service
* @param translate Angular translation service
* @param activatedRoute Angular active route
* @param restService Shared rest service
*/
constructor(
private apollo: Apollo,
Expand All @@ -101,7 +102,8 @@ export class UsersComponent extends UnsubscribeComponent implements OnInit {
private downloadService: DownloadService,
private confirmService: ConfirmService,
private translate: TranslateService,
private activatedRoute: ActivatedRoute
private activatedRoute: ActivatedRoute,
private restService: RestService
) {
super();
}
Expand Down Expand Up @@ -359,9 +361,18 @@ export class UsersComponent extends UnsubscribeComponent implements OnInit {
* @param type The type of file we want ('csv' or 'xlsx')
*/
async onExport(type: 'csv' | 'xlsx') {
this.downloadService.getUsersExport(
type,
this.selection.selected.map((x) => x.id || '').filter((x) => x !== '')
const users = this.selection.selected
.map((x) => x.id || '')
.filter((x) => x !== '');
const queryString = new URLSearchParams({ type }).toString();
this.downloadService.download(
`users.${type}`,
`text/${type};charset=utf-8;`,
this.restService.post(
`download/users?${queryString}`,
{ users },
{ responseType: 'blob' }
)
);
}

Expand Down
2 changes: 1 addition & 1 deletion apps/front-office/src/app/app.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ import {
LoggerService,
CsDocsPropertiesDropdownComponent,
AcceptedValueTypesTextComponent,
CommonServicesService,
} from '@oort-front/shared';
import { CommonServicesService } from '@oort-front/core';

/**
* Main component of Front-office.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ import {
ContextService,
AuthService,
LoggerService,
CommonServicesService,
} from '@oort-front/shared';
import { CommonServicesService } from '@oort-front/core';
import { Subject, debounceTime, filter, skip, takeUntil } from 'rxjs';
import { isEmpty } from 'lodash';
import { ShadowDomService } from '@oort-front/ui';
Expand Down
36 changes: 36 additions & 0 deletions libs/core/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
{
"extends": ["../../.eslintrc.json"],
"ignorePatterns": ["!**/*"],
"overrides": [
{
"files": ["*.ts"],
"rules": {
"@angular-eslint/directive-selector": [
"error",
{
"type": "attribute",
"prefix": "core",
"style": "camelCase"
}
],
"@angular-eslint/component-selector": [
"error",
{
"type": "element",
"prefix": "core",
"style": "kebab-case"
}
]
},
"extends": [
"plugin:@nrwl/nx/angular",
"plugin:@angular-eslint/template/process-inline-templates"
]
},
{
"files": ["*.html"],
"extends": ["plugin:@nrwl/nx/angular-template"],
"rules": {}
}
]
}
11 changes: 11 additions & 0 deletions libs/core/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# core

This library was generated with [Nx](https://nx.dev).

## Lint

`npx nx run core:lint`

## Running unit tests

Run `nx test core` to execute the unit tests.
22 changes: 22 additions & 0 deletions libs/core/jest.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/* eslint-disable */
export default {
displayName: 'core',
preset: '../../jest.preset.js',
setupFilesAfterEnv: ['<rootDir>/src/test-setup.ts'],
globals: {
'ts-jest': {
tsconfig: '<rootDir>/tsconfig.spec.json',
stringifyContentPathRegex: '\\.(html|svg)$',
},
},
coverageDirectory: '../../coverage/libs/core',
transform: {
'^.+\\.(ts|mjs|js|html)$': 'jest-preset-angular',
},
transformIgnorePatterns: ['node_modules/(?!.*\\.mjs$)'],
snapshotSerializers: [
'jest-preset-angular/build/serializers/no-ng-attributes',
'jest-preset-angular/build/serializers/ng-snapshot',
'jest-preset-angular/build/serializers/html-comment',
],
};
31 changes: 31 additions & 0 deletions libs/core/project.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
{
"name": "core",
"$schema": "../node_modules/nx/schemas/project-schema.json",
"projectType": "library",
"sourceRoot": "libs/core/src",
"prefix": "core",
"targets": {
"test": {
"executor": "@nrwl/jest:jest",
"outputs": ["{workspaceRoot}/coverage/{projectRoot}"],
"options": {
"jestConfig": "libs/core/jest.config.ts",
"passWithNoTests": true
},
"configurations": {
"ci": {
"ci": true,
"codeCoverage": true
}
}
},
"lint": {
"executor": "@nrwl/linter:eslint",
"outputs": ["{options.outputFile}"],
"options": {
"lintFilePatterns": ["libs/core/**/*.ts", "libs/core/**/*.html"]
}
}
},
"tags": []
}
3 changes: 3 additions & 0 deletions libs/core/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export * from './lib/components';
export * from './lib/services';
export * from './lib/utils';
1 change: 1 addition & 0 deletions libs/core/src/lib/components/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './snackbar-spinner';
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
export * from './snackbar-spinner.component';
export * from './snackbar-spinner.module';
Original file line number Diff line number Diff line change
@@ -1,15 +1,23 @@
import { CommonModule } from '@angular/common';
import { Component, Inject } from '@angular/core';
import { SnackBarData, SNACKBAR_DATA } from '@oort-front/ui';
import {
SnackBarData,
SNACKBAR_DATA,
SpinnerModule,
IconModule,
} from '@oort-front/ui';
import { BehaviorSubject } from 'rxjs';

/**
* Snackbar to indicate progress of an async task.
* Used for download / upload.
*/
@Component({
selector: 'shared-snackbar-spinner',
standalone: true,
selector: 'core-snackbar-spinner',
templateUrl: './snackbar-spinner.component.html',
styleUrls: ['./snackbar-spinner.component.scss'],
imports: [CommonModule, SpinnerModule, IconModule],
})
export class SnackbarSpinnerComponent {
/** Message displayed in snackbar */
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import { HttpHeaders } from '@angular/common/http';
import { Inject, Injectable } from '@angular/core';
import { RestService } from '../rest/rest.service';
import {
RestService,
DownloadService,
transformGraphQLVariables,
} from '@oort-front/core';
import { Apollo } from 'apollo-angular';
import { InMemoryCache } from '@apollo/client';
import { HttpLink } from 'apollo-angular/http';
import { setContext } from '@apollo/client/link/context';
import { DownloadService } from '../download/download.service';
import transformGraphQLVariables from '../../utils/reference-data/transform-graphql-variables.util';

/**
* Common Services connection.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import { Observable } from 'rxjs';
import { tap } from 'rxjs/operators';
import { SnackbarSpinnerComponent } from '../../components/snackbar-spinner/snackbar-spinner.component';
import { RestService } from '../rest/rest.service';
import { Application } from '../../models/application.model';
import { SnackbarService } from '@oort-front/ui';
import { DOCUMENT } from '@angular/common';

Expand Down Expand Up @@ -207,55 +206,6 @@ export class DownloadService {
});
}

/**
* Downloads file with users from the server
*
* @param type type of the file
* @param users users to export, if any
* @param application application get export users from, if any
*/
getUsersExport(
type: 'csv' | 'xlsx',
users: string[],
application?: Application
): void {
const fileName = application
? `users_${application.name}.${type}`
: `users.${type}`;

const queryString = new URLSearchParams({ type }).toString();
const path = application
? `download/application/${application.id}/users?${queryString}`
: `download/users?${queryString}`;

const { snackBarRef, headers } = this.triggerFileDownloadMessage(
'common.notifications.file.download.processing'
);
const snackBarSpinner = snackBarRef.instance.nestedComponent;

this.restService
.post(path, { users }, { responseType: 'blob', headers })
.subscribe(
(res) => {
const blob = new Blob([res], { type: `text/${type};charset=utf-8;` });
this.saveFile(fileName, blob);
snackBarSpinner.instance.message = this.translate.instant(
'common.notifications.file.download.ready'
);
snackBarSpinner.instance.loading = false;
snackBarRef.instance.triggerSnackBar(SNACKBAR_DURATION);
},
() => {
snackBarSpinner.instance.message = this.translate.instant(
'common.notifications.file.download.error'
);
snackBarSpinner.instance.loading = false;
snackBarSpinner.instance.error = true;
snackBarRef.instance.triggerSnackBar(SNACKBAR_DURATION);
}
);
}

/**
* Saves file from blob
*
Expand Down Expand Up @@ -373,7 +323,7 @@ export class DownloadService {
*/
download(
filename: string,
type: 'text/xlsx;charset=utf-8;',
type: string = 'text/xlsx;charset=utf-8;',
observable: Observable<unknown>
): void {
const { snackBarRef } = this.triggerFileDownloadMessage(
Expand Down
3 changes: 3 additions & 0 deletions libs/core/src/lib/services/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export * from './common-services/common-services.service';
export * from './download/download.service';
export * from './rest/rest.service';
Loading