Skip to content

Commit 8e8cbcd

Browse files
committed
TD-4226 storage update
1 parent 4001d30 commit 8e8cbcd

File tree

4 files changed

+89
-4
lines changed

4 files changed

+89
-4
lines changed

LearningHub.Nhs.WebUI/Controllers/Api/ResourceController.cs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
namespace LearningHub.Nhs.WebUI.Controllers.Api
22
{
33
using System;
4+
using System.Collections.Generic;
45
using System.Threading.Tasks;
56
using LearningHub.Nhs.Models.Enums;
67
using LearningHub.Nhs.Models.Resource;
@@ -557,5 +558,32 @@ public async Task<ActionResult> DeleteResourceProviderAsync(int resourceVersionI
557558
var validationResult = await this.resourceService.DeleteAllResourceVersionProviderAsync(resourceVersionId);
558559
return this.Ok(validationResult);
559560
}
561+
562+
/// <summary>
563+
/// The ArchiveResourceFile.
564+
/// </summary>
565+
/// <param name="filePaths">filePaths.</param>
566+
/// <returns>A <see cref="Task"/> representing the asynchronous operation.</returns>
567+
[HttpPost]
568+
[Route("ArchiveResourceFile")]
569+
public ActionResult ArchiveResourceFile(List<string> filePaths)
570+
{
571+
_ = Task.Run(async () => { await this.fileService.PurgeResourceFile(null, filePaths); });
572+
return this.Ok();
573+
}
574+
575+
/// <summary>
576+
/// The GetObsoleteResourceFile.
577+
/// </summary>
578+
/// <param name="resourceVersionId">The resourceVersionId.</param>
579+
/// <param name="deletedResource">.</param>
580+
/// <returns>The <see cref="T:Task{List{FileTypeViewModel}}"/>.</returns>
581+
[HttpGet]
582+
[Route("GetObsoleteResourceFile/{resourceVersionId}/{deletedResource}")]
583+
public async Task<List<string>> GetObsoleteResourceFile(int resourceVersionId, bool deletedResource)
584+
{
585+
var result = await this.resourceService.GetObsoleteResourceFile(resourceVersionId, deletedResource);
586+
return result;
587+
}
560588
}
561589
}

LearningHub.Nhs.WebUI/Scripts/vuesrc/contribute/Content.vue

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -502,6 +502,8 @@
502502
showError: false,
503503
errorMessage: '',
504504
contributeResourceAVFlag: true,
505+
filePathBeforeFileChange: [] as string[],
506+
filePathAfterFileChange: [] as string[]
505507
}
506508
},
507509
computed: {
@@ -837,6 +839,19 @@
837839
if (uploadResult.resourceType === ResourceType.SCORM) {
838840
this.$store.commit('populateScormDetails', uploadResult.resourceVersionId);
839841
}
842+
843+
if (this.filePathBeforeFileChange.length > 0) {
844+
this.getResourceFilePath('completed');
845+
if (this.filePathBeforeFileChange.length > 0 && this.filePathAfterFileChange.length > 0) {
846+
let filePaths = this.filePathBeforeFileChange.filter(item => !this.filePathAfterFileChange.includes(item));
847+
if (filePaths.length > 0) {
848+
resourceData.archiveResourceFile(filePaths);
849+
this.filePathBeforeFileChange.length = 0;
850+
this.filePathAfterFileChange.length = 0;
851+
}
852+
}
853+
}
854+
840855
} else {
841856
this.fileUploadServerError = 'There was a problem uploading this file to the Learning Hub. Please try again and if it still does not upload, contact the support team.';
842857
this.$store.commit('setSaveStatus', '');
@@ -894,6 +909,7 @@
894909
},
895910
fileChangedScorm() {
896911
(this.$refs.fileUploadScorm as any).click();
912+
this.getResourceFilePath('initialised');
897913
},
898914
childResourceFileChanged(newFile: File) {
899915
this.uploadingFile = newFile;
@@ -943,6 +959,7 @@
943959
fileChanged() {
944960
this.fileUploadRef.value = null;
945961
this.fileUploadRef.click();
962+
this.getResourceFilePath('initialised');
946963
},
947964
childFileUploadError(errorType: FileErrorTypeEnum, customError: string) {
948965
this.fileErrorType = errorType;
@@ -1015,6 +1032,21 @@
10151032
break;
10161033
}
10171034
return errorTitle;
1035+
},
1036+
async getResourceFilePath(fileChangeStatus: string) {
1037+
let resource = this.$store.state.resourceDetail;
1038+
if (resource != null && resource.resourceVersionId > 0 &&(resource.resourceType != this.resourceType.CASE || resource.resourceType != this.resourceType.ASSESSMENT))
1039+
{
1040+
await resourceData.getObsoleteResourceFile(resource.resourceVersionId).then(response => {
1041+
if (fileChangeStatus == 'initialised') {
1042+
this.filePathBeforeFileChange = response;
1043+
}
1044+
else if (fileChangeStatus == 'completed') {
1045+
this.filePathAfterFileChange = response;
1046+
}
1047+
});
1048+
}
1049+
10181050
}
10191051
},
10201052
validations: {

LearningHub.Nhs.WebUI/Scripts/vuesrc/data/resource.ts

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -535,6 +535,29 @@ const getAVUnavailableView = async function (): Promise<string> {
535535
});
536536
};
537537

538+
const getObsoleteResourceFile = async function (id: number): Promise<string[]> {
539+
return await AxiosWrapper.axios.get<string[]>('/api/Resource/GetObsoleteResourceFile/' + id + '/' + true + `?timestamp=${new Date().getTime()}`)
540+
.then(response => {
541+
console.log(response.data);
542+
return response.data;
543+
})
544+
.catch(e => {
545+
console.log('getObsoleteResourceFiles:' + e);
546+
throw e;
547+
});
548+
};
549+
550+
const archiveResourceFile = async function (filepaths: string[]): Promise<boolean> {
551+
const params = {filePaths:filepaths};
552+
return await AxiosWrapper.axios.post('/api/Resource/DuplicateBlocks', params).then(() => {
553+
return true
554+
}).catch(e => {
555+
console.log('archiveResourceFile:' + e);
556+
throw e;
557+
});
558+
};
559+
560+
538561
export const resourceData = {
539562
getContributeConfiguration,
540563
getContributeSettings,
@@ -575,5 +598,7 @@ export const resourceData = {
575598
getMyContributions,
576599
getContributeAVResourceFlag,
577600
getDisplayAVResourceFlag,
578-
getAVUnavailableView
601+
getAVUnavailableView,
602+
getObsoleteResourceFile,
603+
archiveResourceFile
579604
};

WebAPI/LearningHub.Nhs.Services/ResourceService.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1411,7 +1411,7 @@ where deletableCaseFiles.Contains(entry)
14111411
var rvs = await this.resourceVersionRepository.GetResourceVersionsAsync(resourceVersion.ResourceId);
14121412
rvs = rvs.Where(x => x.Id != resourceVersionId && x.PublicationId > 0).OrderByDescending(x => x.PublicationId).ToList();
14131413
var rv = rvs.FirstOrDefault();
1414-
var extendedResourceVersion = await this.GetResourceVersionExtendedViewModelAsync(rv.Id);
1414+
var extendedResourceVersion = rv != null ? await this.GetResourceVersionExtendedViewModelAsync(rv.Id) : null;
14151415
switch (resourceVersion.ResourceType)
14161416
{
14171417
case ResourceTypeEnum.Scorm:
@@ -1432,7 +1432,7 @@ where deletableCaseFiles.Contains(entry)
14321432
}
14331433
else if (rv == null && deletedResource)
14341434
{
1435-
retVal.Add(scormResource.ContentFilePath);
1435+
retVal.Add(scormResource?.File?.FilePath);
14361436
}
14371437

14381438
break;
@@ -1454,7 +1454,7 @@ where deletableCaseFiles.Contains(entry)
14541454
}
14551455
else if (rv == null && deletedResource)
14561456
{
1457-
retVal.Add(htmlResource.ContentFilePath);
1457+
retVal.Add(htmlResource?.File?.FilePath);
14581458
}
14591459

14601460
break;

0 commit comments

Comments
 (0)