Skip to content

Commit

Permalink
Lock/download preview (#311)
Browse files Browse the repository at this point in the history
* create new component and add model file and service file

* build the user interface and calling the api from backend

* add logic for handling data from BE and refactor the UI

* fix the lint error and fix the collapse/hide behaviour

---------

Co-authored-by: HuynhKhoa1601 <[email protected]>
  • Loading branch information
milanmajchrak and HuynhKhoa1601 authored Sep 27, 2023
1 parent 958064f commit a868331
Show file tree
Hide file tree
Showing 24 changed files with 1,025 additions and 58 deletions.
1 change: 1 addition & 0 deletions angular.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
"styles": [
"src/styles/startup.scss",
"src/aai/discojuice/discojuice.css",
"node_modules/font-awesome/css/font-awesome.css",
"node_modules/bootstrap/dist/css/bootstrap.min.css",
{
"input": "src/styles/base-theme.scss",
Expand Down
4 changes: 4 additions & 0 deletions src/app/core/core.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ import { EPerson } from './eperson/models/eperson.model';
import { Group } from './eperson/models/group.model';
import { JsonPatchOperationsBuilder } from './json-patch/builder/json-patch-operations-builder';
import { MetadataField } from './metadata/metadata-field.model';
import { MetadataBitstream } from './metadata/metadata-bitstream.model';
import { MetadataSchema } from './metadata/metadata-schema.model';
import { MetadataService } from './metadata/metadata.service';
import { RegistryService } from './registry/registry.service';
Expand Down Expand Up @@ -133,6 +134,7 @@ import {
import { Registration } from './shared/registration.model';
import { MetadataSchemaDataService } from './data/metadata-schema-data.service';
import { MetadataFieldDataService } from './data/metadata-field-data.service';
import { MetadataBitstreamDataService } from './data/metadata-bitstream-data.service';
import { DsDynamicTypeBindRelationService } from '../shared/form/builder/ds-dynamic-form-ui/ds-dynamic-type-bind-relation.service';
import { TokenResponseParsingService } from './auth/token-response-parsing.service';
import { SubmissionCcLicenseDataService } from './submission/submission-cc-license-data.service';
Expand Down Expand Up @@ -298,6 +300,7 @@ const PROVIDERS = [
SiteRegisterGuard,
MetadataSchemaDataService,
MetadataFieldDataService,
MetadataBitstreamDataService,
TokenResponseParsingService,
ReloadGuard,
EndUserAgreementCurrentUserGuard,
Expand Down Expand Up @@ -341,6 +344,7 @@ export const models =
ResourcePolicy,
MetadataSchema,
MetadataField,
MetadataBitstream,
License,
WorkflowItem,
WorkspaceItem,
Expand Down
Empty file.
82 changes: 82 additions & 0 deletions src/app/core/data/metadata-bitstream-data.service.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
import { Injectable } from '@angular/core';
import { hasValue } from '../../shared/empty.util';
import { PaginatedList } from './paginated-list.model';
import { RemoteData } from './remote-data';
import { RequestService } from './request.service';
import { RemoteDataBuildService } from '../cache/builders/remote-data-build.service';
import { HALEndpointService } from '../shared/hal-endpoint.service';
import { FollowLinkConfig } from '../../shared/utils/follow-link-config.model';
import { Observable } from 'rxjs';
import { RequestParam } from '../cache/models/request-param.model';
import { NoContent } from '../shared/NoContent.model';
import { NotificationsService } from '../../shared/notifications/notifications.service';
import { ObjectCacheService } from '../cache/object-cache.service';
import { METADATA_BITSTREAM } from '../metadata/metadata-bitstream.resource-type';
import { FindListOptions } from './request.models';
import { dataService } from '../cache/builders/build-decorators';
import { MetadataBitstream } from '../metadata/metadata-bitstream.model';
import { DataService } from './data.service';
import { HttpClient } from '@angular/common/http';
import { Store } from '@ngrx/store';
import { CoreState } from '../core.reducers';
import { ChangeAnalyzer } from './change-analyzer';
import { tap } from 'rxjs/operators';

/**
* A service responsible for fetching/sending data from/to the REST API on the metadatafields endpoint
*/
@Injectable()
@dataService(METADATA_BITSTREAM)
export class MetadataBitstreamDataService extends DataService<MetadataBitstream> {
protected store: Store<CoreState>;
protected http: HttpClient;
protected comparator: ChangeAnalyzer<MetadataBitstream>;
protected linkPath = 'metadatabitstreams';
protected searchByHandleLinkPath = 'byHandle';

constructor(
protected requestService: RequestService,
protected rdbService: RemoteDataBuildService,
protected objectCache: ObjectCacheService,
protected halService: HALEndpointService,
protected notificationsService: NotificationsService
) {
super();
}

/**
* Find metadata fields with either the partial metadata field name (e.g. "dc.ti") as query or an exact match to
* at least the schema, element or qualifier
* @param handle optional; an exact match of the prefix of the item identifier (e.g. "123456789/1126")
* @param fileGrpType optional; an exact match of the type of the file(e.g. "TEXT", "THUMBNAIL")
* @param options The options info used to retrieve the fields
* @param useCachedVersionIfAvailable If this is true, the request will only be sent if there's no valid cached version. Defaults to true
* @param reRequestOnStale Whether or not the request should automatically be re-requested after the response becomes stale
* @param linksToFollow List of {@link FollowLinkConfig} that indicate which {@link HALLink}s should be automatically resolved
*/
searchByHandleParams(
handle: string,
fileGrpType: string,
options: FindListOptions = {},
useCachedVersionIfAvailable = true,
reRequestOnStale = true,
...linksToFollow: FollowLinkConfig<any>[]
): Observable<RemoteData<any>> {
const optionParams = Object.assign(new FindListOptions(), options, {
searchParams: [
new RequestParam('handle', hasValue(handle) ? handle : ''),
new RequestParam(
'fileGrpType',
hasValue(fileGrpType) ? fileGrpType : ''
),
],
});
return this.searchBy(
this.searchByHandleLinkPath,
optionParams,
useCachedVersionIfAvailable,
reRequestOnStale,
...linksToFollow
);
}
}
9 changes: 9 additions & 0 deletions src/app/core/metadata/file-info.model.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { autoserialize, autoserializeAs } from 'cerialize';

export class FileInfo {
@autoserialize name: string;
@autoserialize content: any;
@autoserialize size: string;
@autoserialize isDirectory: boolean;
@autoserializeAs('sub') sub: { [key: string]: FileInfo };
}
109 changes: 109 additions & 0 deletions src/app/core/metadata/metadata-bitstream.model.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
import {
autoserialize,
autoserializeAs,
deserialize,
deserializeAs,
} from 'cerialize';
import { ListableObject } from '../../shared/object-collection/shared/listable-object.model';
import { typedObject } from '../cache/builders/build-decorators';
import { GenericConstructor } from '../shared/generic-constructor';
import { HALLink } from '../shared/hal-link.model';
import { HALResource } from '../shared/hal-resource.model';
import { ResourceType } from '../shared/resource-type';
import { excludeFromEquals } from '../utilities/equals.decorators';
import { METADATA_BITSTREAM } from './metadata-bitstream.resource-type';
import { FileInfo } from './file-info.model';

/**
* Class the represents a File
*/
// export class FileInfo {
// @autoserialize name: string;
// @autoserialize content: any;
// @autoserialize size: string;
// @autoserialize isDirectory: boolean;
// @autoserializeAs('sub') sub: { [key: string]: FileInfo };
// }

/**
* Class that represents a MetadataBitstream
*/
@typedObject
export class MetadataBitstream extends ListableObject implements HALResource {
static type = METADATA_BITSTREAM;

/**
* The object type
*/
@excludeFromEquals
@autoserialize
type: ResourceType;

/**
* The identifier of this metadata field
*/
@autoserialize
id: number;

/**
* The name of this bitstream
*/
@autoserialize
name: string;

/**
* The description of this bitstream
*/
@autoserialize
description: string;

/**
* The fileSize of this bitstream
*/
@autoserialize
fileSize: string;

/**
* The checksum of this bitstream
*/
@autoserialize
checksum: string;

/**
* The fileInfo of this bitstream
*/
@autoserializeAs(FileInfo, 'fileInfo') fileInfo: FileInfo[];

/**
* The format of this bitstream
*/
@autoserialize
format: string;

/**
* The href of this bitstream
*/
@autoserialize
href: string;

/**
* The canPreview of this bitstream
*/
@autoserialize
canPreview: boolean;

/**
* The {@link HALLink}s for this MetadataField
*/
@deserialize
_links: {
self: HALLink;
schema: HALLink;
};

getRenderTypes(): (string | GenericConstructor<ListableObject>)[] {
return [this.constructor as GenericConstructor<ListableObject>];
}
}
export { FileInfo };

10 changes: 10 additions & 0 deletions src/app/core/metadata/metadata-bitstream.resource-type.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { ResourceType } from '../shared/resource-type';

/**
* The resource type for MetadataBitstream
*
* Needs to be in a separate file to prevent circular
* dependencies in webpack.
*/

export const METADATA_BITSTREAM = new ResourceType('metadatabitstream');
Loading

0 comments on commit a868331

Please sign in to comment.