Skip to content

Commit

Permalink
[MS] Updated how to show single file history
Browse files Browse the repository at this point in the history
  • Loading branch information
Max-7 committed Oct 29, 2024
1 parent b7d7e4c commit 60caa71
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 34 deletions.
1 change: 1 addition & 0 deletions client/src/components/files/FileDropZone.vue
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ async function onDrop(event: DragEvent): Promise<void> {
if (props.disabled) {
return;
}
event.stopPropagation();
dragEnterCount.value = 0;
const imports = await getFilesFromDrop(event, props.currentPath);
if (imports.length) {
Expand Down
8 changes: 7 additions & 1 deletion client/src/views/files/FoldersPage.vue
Original file line number Diff line number Diff line change
Expand Up @@ -1148,7 +1148,13 @@ async function showHistory(entries: EntryModel[]): Promise<void> {
return;
}

await navigateTo(Routes.History, { query: { documentPath: entries[0].path, workspaceHandle: workspaceInfo.value.handle } });
await navigateTo(Routes.History, {
query: {
documentPath: entries[0].path,
workspaceHandle: workspaceInfo.value.handle,
selectFile: entries[0].isFile() ? entries[0].name : undefined,
},
});
}

async function openEntries(entries: EntryModel[]): Promise<void> {
Expand Down
76 changes: 43 additions & 33 deletions client/src/views/workspaces/WorkspaceHistoryPage.vue
Original file line number Diff line number Diff line change
Expand Up @@ -143,14 +143,14 @@
<script setup lang="ts">
import { IonPage, IonList, IonLabel, IonButtons, IonIcon, IonButton, IonListHeader, IonContent, IonText } from '@ionic/vue';
import { computed, onBeforeUnmount, onMounted, ref, Ref, inject } from 'vue';
import { FsPath, Path, getWorkspaceInfo, StartedWorkspaceInfo, statFolderChildrenAt, entryStatAt } from '@/parsec';
import { FsPath, Path, getWorkspaceInfo, StartedWorkspaceInfo, statFolderChildrenAt, entryStatAt, EntryName } from '@/parsec';
import { MsCheckbox, MsSpinner, MsSearchInput, askQuestion, Answer, MsDatetimePicker } from 'megashark-lib';
import { DateTime } from 'luxon';
import { RouterPathNode } from '@/components/header/HeaderBreadcrumbs.vue';
import HeaderBreadcrumbs from '@/components/header/HeaderBreadcrumbs.vue';
import { WorkspaceHistoryEntryCollection, WorkspaceHistoryEntryModel, HistoryFileListItem } from '@/components/files';
import { chevronBack, chevronForward, warning } from 'ionicons/icons';
import { currentRouteIs, getDocumentPath, getWorkspaceHandle, Routes } from '@/router';
import { currentRouteIs, getCurrentRouteQuery, getDocumentPath, getWorkspaceHandle, Routes } from '@/router';
import { FileOperationManager, FileOperationManagerKey } from '@/services/fileOperationManager';
import { SortProperty } from '@/components/users';

Expand All @@ -168,8 +168,8 @@ const entries: Ref<WorkspaceHistoryEntryCollection<WorkspaceHistoryEntryModel>>
const querying = ref(false);
let timeoutId: number | null = null;
const resultFromSearch = ref(false);
const currentIsFile = ref(false);
const error = ref('');
const selectEntry: Ref<EntryName> = ref('');

const allSelected = computed(() => {
return entries.value.selectedCount() === entries.value.entriesCount();
Expand All @@ -188,8 +188,14 @@ onMounted(async () => {
} else {
console.error('Failed to retrieve workspace info');
}
} else {
return;
}
currentPath.value = getDocumentPath() ?? '/';
const query = getCurrentRouteQuery();
if (query.selectFile) {
selectEntry.value = query.selectFile;
}

await listCurrentPath();
});
Expand Down Expand Up @@ -225,43 +231,43 @@ async function listCurrentPath(): Promise<void> {
return;
}
error.value = '';

if (statsResult.value.isFile()) {
currentIsFile.value = true;
(statsResult.value as WorkspaceHistoryEntryModel).isSelected = false;
entries.value.replace([statsResult.value as WorkspaceHistoryEntryModel]);
} else {
const breadcrumbs = await Path.parse(currentPath.value);

const result = await statFolderChildrenAt(workspaceHandle, currentPath.value, DateTime.fromJSDate(selectedDateTime.value));
if (result.ok) {
const newEntries: WorkspaceHistoryEntryModel[] = [];
for (const entry of result.value) {
(entry as WorkspaceHistoryEntryModel).isSelected = false;
newEntries.push(entry as WorkspaceHistoryEntryModel);
}
entries.value.replace(newEntries);
entries.value.sort(SortProperty.Name as any, true);
// If the current path is set to a file, we instead set it to the parent dir
currentPath.value = await Path.parent(currentPath.value);
}

const breadcrumbs = await Path.parse(currentPath.value);

const result = await statFolderChildrenAt(workspaceHandle, currentPath.value, DateTime.fromJSDate(selectedDateTime.value));
if (result.ok) {
const newEntries: WorkspaceHistoryEntryModel[] = [];
for (const entry of result.value) {
(entry as WorkspaceHistoryEntryModel).isSelected = Boolean(selectEntry.value && selectEntry.value === entry.name);
newEntries.push(entry as WorkspaceHistoryEntryModel);
}
entries.value.replace(newEntries);
entries.value.sort(SortProperty.Name as any, true);
}

let path = '/';
headerPath.value = [];
let path = '/';
headerPath.value = [];
headerPath.value.push({
id: 0,
display: workspaceInfo.value.currentName,
name: '',
query: { documentPath: path },
});
let id = 1;
for (const breadcrumb of breadcrumbs) {
path = await Path.join(path, breadcrumb);
headerPath.value.push({
id: 0,
display: workspaceInfo.value.currentName,
id: id,
display: breadcrumb === '/' ? '' : breadcrumb,
name: '',
query: { documentPath: path },
});
let id = 1;
for (const breadcrumb of breadcrumbs) {
path = await Path.join(path, breadcrumb);
headerPath.value.push({
id: id,
display: breadcrumb === '/' ? '' : breadcrumb,
name: '',
query: { documentPath: path },
});
id += 1;
}
id += 1;
}
} finally {
querying.value = false;
Expand All @@ -276,6 +282,7 @@ async function forward(): Promise<void> {
}
backStack.push(currentPath.value);
currentPath.value = forwardPath;
selectEntry.value = '';
await listCurrentPath();
}

Expand All @@ -287,11 +294,13 @@ async function back(): Promise<void> {
}
forwardStack.push(currentPath.value);
currentPath.value = backPath;
selectEntry.value = '';
await listCurrentPath();
}

async function onPathChange(node: RouterPathNode): Promise<void> {
forwardStack.splice(0, forwardStack.length);
selectEntry.value = '';
if (node.query && node.query.documentPath) {
currentPath.value = node.query.documentPath;
await listCurrentPath();
Expand All @@ -307,6 +316,7 @@ async function onEntryClicked(entry: WorkspaceHistoryEntryModel): Promise<void>
console.log('Click on file');
} else {
backStack.push(currentPath.value);
selectEntry.value = '';
currentPath.value = await Path.join(currentPath.value, entry.name);
await listCurrentPath();
}
Expand Down

0 comments on commit 60caa71

Please sign in to comment.