Skip to content

Commit

Permalink
feat(files-manager): some fix on files renaming
Browse files Browse the repository at this point in the history
  • Loading branch information
NicolasRichel committed Jun 4, 2021
1 parent c0b9fc2 commit 0b98745
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 12 deletions.
4 changes: 2 additions & 2 deletions src/components/specific/files/files-table/FilesTable.vue
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
<template #cell-type="{ row: file }">
<FileTypeCell :file="file" />
</template>
<template #cell-creator="{ row: { creator } }">
{{ creator ? `${creator.firstname} ${creator.lastname[0]}.` : "?" }}
<template #cell-creator="{ row: { createdBy } }">
{{ createdBy ? `${createdBy.firstname} ${createdBy.lastname[0]}.` : "?" }}
</template>
<template #cell-tags="{ row: file }">
<FileTagsCell :file="file" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
>
<BIMDataIcon
v-if="file.type === 'Folder'"
class="file-name-cell__icon-folder"
class="file-name-cell__content__icon-folder"
name="folder"
size="m"
/>
Expand Down Expand Up @@ -102,8 +102,7 @@ export default {
if (fileName.value) {
loading.value = true;
await updateFile(props.project, {
id: props.file.id,
type: props.file.type,
...props.file,
name: fileName.value
});
closeUpdateForm();
Expand Down
25 changes: 21 additions & 4 deletions src/server/FileService.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,22 @@
import apiClient from "./api-client";

const FOLDER_UPDATABLE_FIELDS = ["name", "parentId"];
const DOCUMENT_UPDATABLE_FIELDS = ["name", "description", "parentId"];

function createPayload(object, allowedFields) {
const payload = {};
for (const field of allowedFields) {
payload[field] = object[field];
}
return payload;
}

const folderUpdatePayload = folder =>
createPayload(folder, FOLDER_UPDATABLE_FIELDS);

const documentUpdatePayload = document =>
createPayload(document, DOCUMENT_UPDATABLE_FIELDS);

class FileService {
fetchFileStructure(project) {
return apiClient.collaborationApi.getProjectDMSTree({
Expand All @@ -24,7 +41,7 @@ class FileService {
cloudPk: project.cloud.id,
projectPk: project.id,
id: folder.id,
data: folder
data: folderUpdatePayload(folder)
})
)
);
Expand Down Expand Up @@ -52,21 +69,21 @@ class FileService {
}

updateDocuments(project, documents) {
documents = [].concat(documents);
documents = [documents].flat();
return Promise.all(
documents.map(document =>
apiClient.collaborationApi.updateDocument({
cloudPk: project.cloud.id,
projectPk: project.id,
id: document.id,
data: document
data: documentUpdatePayload(document)
})
)
);
}

deleteDocuments(project, documents) {
documents = [].concat(documents);
documents = [documents].flat();
return Promise.all(
documents.map(document =>
apiClient.collaborationApi.deleteDocument({
Expand Down
9 changes: 9 additions & 0 deletions src/state/files.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { reactive, readonly, toRefs } from "@vue/reactivity";
import FileService from "@/server/FileService";
import { useModels } from "@/state/models";
import { FileStructureHandler } from "@/utils/file-structure";

const state = reactive({
Expand Down Expand Up @@ -61,6 +62,14 @@ const createDocument = async (project, document) => {
const updateDocuments = async (project, documents) => {
const newDocuments = await FileService.updateDocuments(project, documents);
softUpdateFileStructure("update", documents);

// Update corresponding models if any
const { fetchModelByID, softUpdateModels } = useModels();
const modelDocs = [documents].flat().filter(doc => doc.type === "Ifc");
Promise.all(modelDocs.map(doc => fetchModelByID(project, doc.ifcId))).then(
softUpdateModels
);

return newDocuments;
};

Expand Down
2 changes: 1 addition & 1 deletion src/state/models.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ const deleteModels = async (project, models) => {
};

const softDeleteModels = models => {
const modelIDs = [].concat(models).map(m => m.id);
const modelIDs = [models].flat().map(m => m.id);
state.projectModels = state.projectModels.filter(
model => !modelIDs.includes(model.id)
);
Expand Down
4 changes: 2 additions & 2 deletions src/views/project-board/project-overview/ProjectOverview.vue
Original file line number Diff line number Diff line change
Expand Up @@ -71,15 +71,15 @@ export default {
ModelsOverview,
ProjectUsersManager
},
setup(props) {
setup() {
const { currentProject, projectUsers, projectInvitations } = useProjects();
const { loadProjectModels, projectModels } = useModels();
let reloadDebounce = null;
const reloadModels = () => {
clearTimeout(reloadDebounce);
reloadDebounce = setTimeout(async () => {
await loadProjectModels(props.project);
await loadProjectModels(currentProject.value);
}, 1000);
};
Expand Down

0 comments on commit 0b98745

Please sign in to comment.