2021-02-24 19:06:48 +01:00
|
|
|
<template>
|
|
|
|
<div class="activity-item">
|
2022-08-26 16:08:58 +02:00
|
|
|
<o-icon :icon="'link'" :variant="iconColor" custom-size="24" />
|
|
|
|
<div class="mt-1 ml-2 prose dark:prose-invert prose-p:m-0">
|
2022-07-12 10:55:28 +02:00
|
|
|
<i18n-t :keypath="translation" tag="p">
|
|
|
|
<template #resource>
|
|
|
|
<router-link v-if="activity.object" :to="path">{{
|
|
|
|
subjectParams.resource_title
|
|
|
|
}}</router-link>
|
|
|
|
<b v-else>{{ subjectParams.resource_title }}</b>
|
|
|
|
</template>
|
|
|
|
<template #new_path>
|
|
|
|
<router-link v-if="activity.object" :to="path">{{
|
|
|
|
parentDirectory
|
|
|
|
}}</router-link>
|
|
|
|
<b v-else>{{ parentDirectory }}</b>
|
|
|
|
</template>
|
|
|
|
<template #old_resource_title>
|
|
|
|
<router-link
|
|
|
|
v-if="activity.object && subjectParams.old_resource_title"
|
|
|
|
:to="path"
|
|
|
|
>{{ subjectParams.old_resource_title }}</router-link
|
|
|
|
>
|
|
|
|
<b v-else-if="subjectParams.old_resource_title">{{
|
|
|
|
subjectParams.old_resource_title
|
|
|
|
}}</b>
|
|
|
|
</template>
|
2021-02-24 19:06:48 +01:00
|
|
|
|
2022-07-12 10:55:28 +02:00
|
|
|
<template #profile>
|
|
|
|
<popover-actor-card :actor="activity.author" :inline="true">
|
|
|
|
<b>
|
|
|
|
{{
|
|
|
|
$t("{'@'}{username}", {
|
|
|
|
username: usernameWithDomain(activity.author),
|
|
|
|
})
|
|
|
|
}}</b
|
|
|
|
></popover-actor-card
|
|
|
|
></template
|
|
|
|
></i18n-t
|
2021-02-24 19:06:48 +01:00
|
|
|
>
|
2022-07-12 10:55:28 +02:00
|
|
|
<small class="activity-date">{{
|
|
|
|
formatTimeString(activity.insertedAt)
|
2021-02-24 19:06:48 +01:00
|
|
|
}}</small>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</template>
|
2022-07-12 10:55:28 +02:00
|
|
|
<script lang="ts" setup>
|
2021-02-24 19:06:48 +01:00
|
|
|
import { usernameWithDomain } from "@/types/actor";
|
|
|
|
import { ActivityResourceSubject } from "@/types/enums";
|
|
|
|
import RouteName from "../../router/name";
|
|
|
|
import PopoverActorCard from "../Account/PopoverActorCard.vue";
|
2022-07-12 10:55:28 +02:00
|
|
|
import { formatTimeString } from "@/filters/datetime";
|
|
|
|
import {
|
|
|
|
useIsActivityAuthorCurrentActor,
|
|
|
|
useActivitySubjectParams,
|
|
|
|
} from "@/composition/activity";
|
|
|
|
import { IActivity } from "@/types/activity.model";
|
|
|
|
import { computed } from "vue";
|
|
|
|
import { IResource } from "@/types/resource";
|
2021-02-24 19:06:48 +01:00
|
|
|
|
2022-07-12 10:55:28 +02:00
|
|
|
const props = defineProps<{
|
|
|
|
activity: IActivity;
|
|
|
|
}>();
|
2021-02-24 19:06:48 +01:00
|
|
|
|
2022-07-12 10:55:28 +02:00
|
|
|
const isAuthorCurrentActor = useIsActivityAuthorCurrentActor()(props.activity);
|
|
|
|
|
|
|
|
const subjectParams = useActivitySubjectParams()(props.activity);
|
|
|
|
|
|
|
|
const resource = computed(() => props.activity.object as IResource);
|
|
|
|
|
|
|
|
const translation = computed((): string | undefined => {
|
|
|
|
switch (props.activity.subject) {
|
|
|
|
case ActivityResourceSubject.RESOURCE_CREATED:
|
|
|
|
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
|
|
// @ts-ignore
|
|
|
|
if (props.activity?.object?.type === "folder") {
|
|
|
|
if (isAuthorCurrentActor) {
|
|
|
|
return "You created the folder {resource}.";
|
2021-02-24 19:06:48 +01:00
|
|
|
}
|
2022-07-12 10:55:28 +02:00
|
|
|
return "{profile} created the folder {resource}.";
|
|
|
|
}
|
|
|
|
if (isAuthorCurrentActor) {
|
|
|
|
return "You created the resource {resource}.";
|
|
|
|
}
|
|
|
|
return "{profile} created the resource {resource}.";
|
|
|
|
case ActivityResourceSubject.RESOURCE_MOVED:
|
|
|
|
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
|
|
// @ts-ignore
|
|
|
|
if (props.activity?.object?.type === "folder") {
|
|
|
|
if (parentDirectory.value === null) {
|
|
|
|
if (isAuthorCurrentActor) {
|
|
|
|
return "You moved the folder {resource} to the root folder.";
|
2021-02-24 19:06:48 +01:00
|
|
|
}
|
2022-07-12 10:55:28 +02:00
|
|
|
return "{profile} moved the folder {resource} to the root folder.";
|
2021-02-24 19:06:48 +01:00
|
|
|
}
|
2022-07-12 10:55:28 +02:00
|
|
|
if (isAuthorCurrentActor) {
|
|
|
|
return "You moved the folder {resource} into {new_path}.";
|
2021-02-24 19:06:48 +01:00
|
|
|
}
|
2022-07-12 10:55:28 +02:00
|
|
|
return "{profile} moved the folder {resource} into {new_path}.";
|
|
|
|
}
|
|
|
|
if (parentDirectory.value === null) {
|
|
|
|
if (isAuthorCurrentActor) {
|
|
|
|
return "You moved the resource {resource} to the root folder.";
|
2021-02-24 19:06:48 +01:00
|
|
|
}
|
2022-07-12 10:55:28 +02:00
|
|
|
return "{profile} moved the resource {resource} to the root folder.";
|
|
|
|
}
|
|
|
|
if (isAuthorCurrentActor) {
|
|
|
|
return "You moved the resource {resource} into {new_path}.";
|
|
|
|
}
|
|
|
|
return "{profile} moved the resource {resource} into {new_path}.";
|
|
|
|
case ActivityResourceSubject.RESOURCE_UPDATED:
|
|
|
|
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
|
|
// @ts-ignore
|
|
|
|
if (props.activity?.object?.type === "folder") {
|
|
|
|
if (isAuthorCurrentActor) {
|
|
|
|
return "You renamed the folder from {old_resource_title} to {resource}.";
|
2021-02-24 19:06:48 +01:00
|
|
|
}
|
2022-07-12 10:55:28 +02:00
|
|
|
return "{profile} renamed the folder from {old_resource_title} to {resource}.";
|
|
|
|
}
|
|
|
|
if (isAuthorCurrentActor) {
|
|
|
|
return "You renamed the resource from {old_resource_title} to {resource}.";
|
|
|
|
}
|
|
|
|
return "{profile} renamed the resource from {old_resource_title} to {resource}.";
|
|
|
|
case ActivityResourceSubject.RESOURCE_DELETED:
|
|
|
|
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
|
|
// @ts-ignore
|
|
|
|
if (props.activity?.object?.type === "folder") {
|
|
|
|
if (isAuthorCurrentActor) {
|
|
|
|
return "You deleted the folder {resource}.";
|
2021-02-24 19:06:48 +01:00
|
|
|
}
|
2022-07-12 10:55:28 +02:00
|
|
|
return "{profile} deleted the folder {resource}.";
|
|
|
|
}
|
|
|
|
if (isAuthorCurrentActor) {
|
|
|
|
return "You deleted the resource {resource}.";
|
|
|
|
}
|
|
|
|
return "{profile} deleted the resource {resource}.";
|
|
|
|
default:
|
|
|
|
return undefined;
|
2021-02-24 19:06:48 +01:00
|
|
|
}
|
2022-07-12 10:55:28 +02:00
|
|
|
});
|
2021-02-24 19:06:48 +01:00
|
|
|
|
2022-07-12 10:55:28 +02:00
|
|
|
const iconColor = computed((): string | undefined => {
|
|
|
|
switch (props.activity.subject) {
|
|
|
|
case ActivityResourceSubject.RESOURCE_CREATED:
|
2022-08-26 16:08:58 +02:00
|
|
|
return "success";
|
2022-07-12 10:55:28 +02:00
|
|
|
case ActivityResourceSubject.RESOURCE_MOVED:
|
|
|
|
case ActivityResourceSubject.RESOURCE_UPDATED:
|
2022-08-26 16:08:58 +02:00
|
|
|
return "grey";
|
2022-07-12 10:55:28 +02:00
|
|
|
case ActivityResourceSubject.RESOURCE_DELETED:
|
2022-08-26 16:08:58 +02:00
|
|
|
return "danger";
|
2022-07-12 10:55:28 +02:00
|
|
|
default:
|
|
|
|
return undefined;
|
2021-02-24 19:06:48 +01:00
|
|
|
}
|
2022-07-12 10:55:28 +02:00
|
|
|
});
|
2021-02-24 19:06:48 +01:00
|
|
|
|
2022-07-12 10:55:28 +02:00
|
|
|
const path = computed(() => {
|
|
|
|
const localPath = parentPath(resource.value?.path);
|
|
|
|
if (localPath === "") {
|
2021-02-24 19:06:48 +01:00
|
|
|
return {
|
2022-07-12 10:55:28 +02:00
|
|
|
name: RouteName.RESOURCE_FOLDER_ROOT,
|
2021-02-24 19:06:48 +01:00
|
|
|
params: {
|
2022-07-12 10:55:28 +02:00
|
|
|
preferredUsername: usernameWithDomain(props.activity.group),
|
2021-02-24 19:06:48 +01:00
|
|
|
},
|
|
|
|
};
|
|
|
|
}
|
2022-07-12 10:55:28 +02:00
|
|
|
return {
|
|
|
|
name: RouteName.RESOURCE_FOLDER,
|
|
|
|
params: {
|
|
|
|
path: localPath,
|
|
|
|
preferredUsername: usernameWithDomain(props.activity.group),
|
|
|
|
},
|
|
|
|
};
|
|
|
|
});
|
2021-02-24 19:06:48 +01:00
|
|
|
|
2022-07-12 10:55:28 +02:00
|
|
|
const parentPath = (parent: string | undefined): string | undefined => {
|
|
|
|
if (!parent) return undefined;
|
|
|
|
const localPath = parent.split("/");
|
|
|
|
localPath.pop();
|
|
|
|
return localPath.join("/").replace(/^\//, "");
|
|
|
|
};
|
2021-02-24 19:06:48 +01:00
|
|
|
|
2022-07-12 10:55:28 +02:00
|
|
|
const parentDirectory = computed((): string | undefined | null => {
|
|
|
|
if (subjectParams.resource_path) {
|
|
|
|
const parentPathResult = parentPath(subjectParams.resource_path);
|
|
|
|
const directory = parentPathResult?.split("/");
|
|
|
|
const res = directory?.pop();
|
|
|
|
res === "" ? null : res;
|
2021-02-24 19:06:48 +01:00
|
|
|
}
|
2022-07-12 10:55:28 +02:00
|
|
|
return null;
|
|
|
|
});
|
2021-02-24 19:06:48 +01:00
|
|
|
</script>
|
|
|
|
<style lang="scss" scoped>
|
|
|
|
@import "./activity.scss";
|
|
|
|
</style>
|