Skip to content
Merged
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
28 changes: 28 additions & 0 deletions LearningHub.Nhs.WebUI/Controllers/Api/ResourceController.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
namespace LearningHub.Nhs.WebUI.Controllers.Api
{
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using LearningHub.Nhs.Models.Enums;
using LearningHub.Nhs.Models.Resource;
Expand Down Expand Up @@ -557,5 +558,32 @@ public async Task<ActionResult> DeleteResourceProviderAsync(int resourceVersionI
var validationResult = await this.resourceService.DeleteAllResourceVersionProviderAsync(resourceVersionId);
return this.Ok(validationResult);
}

/// <summary>
/// The ArchiveResourceFile.
/// </summary>
/// <param name="filePaths">filePaths.</param>
/// <returns>A <see cref="Task"/> representing the asynchronous operation.</returns>
[HttpPost]
[Route("ArchiveResourceFile")]
public ActionResult ArchiveResourceFile(List<string> filePaths)
{
_ = Task.Run(async () => { await this.fileService.PurgeResourceFile(null, filePaths); });
return this.Ok();
}

/// <summary>
/// The GetObsoleteResourceFile.
/// </summary>
/// <param name="resourceVersionId">The resourceVersionId.</param>
/// <param name="deletedResource">.</param>
/// <returns>The <see cref="T:Task{List{FileTypeViewModel}}"/>.</returns>
[HttpGet]
[Route("GetObsoleteResourceFile/{resourceVersionId}/{deletedResource}")]
public async Task<List<string>> GetObsoleteResourceFile(int resourceVersionId, bool deletedResource)
{
var result = await this.resourceService.GetObsoleteResourceFile(resourceVersionId, deletedResource);
return result;
}
}
}
32 changes: 32 additions & 0 deletions LearningHub.Nhs.WebUI/Scripts/vuesrc/contribute/Content.vue
Original file line number Diff line number Diff line change
Expand Up @@ -502,6 +502,8 @@
showError: false,
errorMessage: '',
contributeResourceAVFlag: true,
filePathBeforeFileChange: [] as string[],
filePathAfterFileChange: [] as string[]
}
},
computed: {
Expand Down Expand Up @@ -837,6 +839,19 @@
if (uploadResult.resourceType === ResourceType.SCORM) {
this.$store.commit('populateScormDetails', uploadResult.resourceVersionId);
}

if (this.filePathBeforeFileChange.length > 0) {
this.getResourceFilePath('completed');
if (this.filePathBeforeFileChange.length > 0 && this.filePathAfterFileChange.length > 0) {
let filePaths = this.filePathBeforeFileChange.filter(item => !this.filePathAfterFileChange.includes(item));
if (filePaths.length > 0) {
resourceData.archiveResourceFile(filePaths);
this.filePathBeforeFileChange.length = 0;
this.filePathAfterFileChange.length = 0;
}
}
}

} else {
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.';
this.$store.commit('setSaveStatus', '');
Expand Down Expand Up @@ -894,6 +909,7 @@
},
fileChangedScorm() {
(this.$refs.fileUploadScorm as any).click();
this.getResourceFilePath('initialised');
},
childResourceFileChanged(newFile: File) {
this.uploadingFile = newFile;
Expand Down Expand Up @@ -943,6 +959,7 @@
fileChanged() {
this.fileUploadRef.value = null;
this.fileUploadRef.click();
this.getResourceFilePath('initialised');
},
childFileUploadError(errorType: FileErrorTypeEnum, customError: string) {
this.fileErrorType = errorType;
Expand Down Expand Up @@ -1015,6 +1032,21 @@
break;
}
return errorTitle;
},
async getResourceFilePath(fileChangeStatus: string) {
let resource = this.$store.state.resourceDetail;
if (resource != null && resource.resourceVersionId > 0 &&(resource.resourceType != this.resourceType.CASE || resource.resourceType != this.resourceType.ASSESSMENT))
{
await resourceData.getObsoleteResourceFile(resource.resourceVersionId).then(response => {
if (fileChangeStatus == 'initialised') {
this.filePathBeforeFileChange = response;
}
else if (fileChangeStatus == 'completed') {
this.filePathAfterFileChange = response;
}
});
}

}
},
validations: {
Expand Down
27 changes: 26 additions & 1 deletion LearningHub.Nhs.WebUI/Scripts/vuesrc/data/resource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -535,6 +535,29 @@ const getAVUnavailableView = async function (): Promise<string> {
});
};

const getObsoleteResourceFile = async function (id: number): Promise<string[]> {
return await AxiosWrapper.axios.get<string[]>('/api/Resource/GetObsoleteResourceFile/' + id + '/' + true + `?timestamp=${new Date().getTime()}`)
.then(response => {
console.log(response.data);
return response.data;
})
.catch(e => {
console.log('getObsoleteResourceFiles:' + e);
throw e;
});
};

const archiveResourceFile = async function (filepaths: string[]): Promise<boolean> {
const params = {filePaths:filepaths};
return await AxiosWrapper.axios.post('/api/Resource/DuplicateBlocks', params).then(() => {
return true
}).catch(e => {
console.log('archiveResourceFile:' + e);
throw e;
});
};


export const resourceData = {
getContributeConfiguration,
getContributeSettings,
Expand Down Expand Up @@ -575,5 +598,7 @@ export const resourceData = {
getMyContributions,
getContributeAVResourceFlag,
getDisplayAVResourceFlag,
getAVUnavailableView
getAVUnavailableView,
getObsoleteResourceFile,
archiveResourceFile
};
6 changes: 3 additions & 3 deletions WebAPI/LearningHub.Nhs.Services/ResourceService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1411,7 +1411,7 @@ where deletableCaseFiles.Contains(entry)
var rvs = await this.resourceVersionRepository.GetResourceVersionsAsync(resourceVersion.ResourceId);
rvs = rvs.Where(x => x.Id != resourceVersionId && x.PublicationId > 0).OrderByDescending(x => x.PublicationId).ToList();
var rv = rvs.FirstOrDefault();
var extendedResourceVersion = await this.GetResourceVersionExtendedViewModelAsync(rv.Id);
var extendedResourceVersion = rv != null ? await this.GetResourceVersionExtendedViewModelAsync(rv.Id) : null;
switch (resourceVersion.ResourceType)
{
case ResourceTypeEnum.Scorm:
Expand All @@ -1432,7 +1432,7 @@ where deletableCaseFiles.Contains(entry)
}
else if (rv == null && deletedResource)
{
retVal.Add(scormResource.ContentFilePath);
retVal.Add(scormResource?.File?.FilePath);
}

break;
Expand All @@ -1454,7 +1454,7 @@ where deletableCaseFiles.Contains(entry)
}
else if (rv == null && deletedResource)
{
retVal.Add(htmlResource.ContentFilePath);
retVal.Add(htmlResource?.File?.FilePath);
}

break;
Expand Down