Skip to content
Open
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
24 changes: 16 additions & 8 deletions src/components/SelectActivity.vue
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@
<strong>
{{ aiplan.UserName(m.actor_detail).join(' ') + ' ' }}
</strong>
<span v-html="getHistoryText(m, workspaceProjects)"> </span>
<span v-html="entityActivityRenderer(m, workspaceProjects)">
</span>
</q-item-label>

<q-item-label caption class="sub-text">{{
Expand All @@ -57,8 +58,12 @@
</q-btn>
</q-list>
<div v-else class="q-mt-lg q-mb-md q-px-sm">
<span v-if="type === 'tasks'" class="body-1 header-title-text">У этой задачи пока нет активностей</span>
<span v-if="type === 'docs'" class="body-1 header-title-text">Для этого документа еще нет активности</span>
<span v-if="type === 'tasks'" class="body-1 header-title-text"
>У этой задачи пока нет активностей</span
>
<span v-if="type === 'docs'" class="body-1 header-title-text"
>Для этого документа еще нет активности</span
>
</div>
</div>
</template>
Expand All @@ -76,7 +81,10 @@ import { useWorkspaceStore } from 'stores/workspace-store';
import aiplan from 'src/utils/aiplan';
import { formatDateTime } from 'src/utils/time';
import { setIntervalFunction } from 'src/utils/helpers';
import { getIcon, getHistoryText } from 'src/utils/strings';
import {
getIcon,
entityActivityRenderer,
} from 'src/components/activity/entityActivity';

//components - icon
import AvatarImage from './AvatarImage.vue';
Expand All @@ -86,10 +94,10 @@ defineProps({
type: Object,
required: true,
},
type: {
type: String,
required: true,
}
type: {
type: String,
required: true,
},
});

const emits = defineEmits<{
Expand Down
69 changes: 69 additions & 0 deletions src/components/activity/entityActivity/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
import { HistoryEntry, HistoryRenderer, ProjectBase } from './types';

import { renderBlocks } from './renders/blocks';
import { renderAssignees, renderWatchers } from './renders/assignees';
import {
renderCompletedAt,
renderStartDate,
renderTargetDate,
} from './renders/dates';
import {
renderLinked,
renderLink,
renderLinkUrl,
renderLinkTitle,
} from './renders/links';
import { renderAttachment } from './renders/attachments';
import { renderParent, renderBlocking, renderSubIssue } from './renders/issues';
import { renderComment } from './renders/comments';
import { renderLabels, renderLabel } from './renders/labels';
import { renderSprint } from './renders/sprints';
import { renderDoc, renderSeqId, renderDescription } from './renders/docs';
import { renderIssueTransfer, renderProject } from './renders/projects';
import { renderPriority, renderDefault } from './renders/priority';

const fieldRenderers: Record<string, HistoryRenderer> = {
blocks: renderBlocks,
assignees: renderAssignees,
watchers: renderWatchers,
completed_at: renderCompletedAt,
start_date: renderStartDate,
target_date: renderTargetDate,
linked: renderLinked,
link: renderLink,
link_url: renderLinkUrl,
link_title: renderLinkTitle,
attachment: renderAttachment,
parent: renderParent,
blocking: renderBlocking,
sub_issue: renderSubIssue,
comment: renderComment,
labels: renderLabels,
label: renderLabel,
sprint: renderSprint,
doc: renderDoc,
seq_id: renderSeqId,
description: renderDescription,
issue_transfer: renderIssueTransfer,
project: renderProject,
priority: renderPriority,
};

export function entityActivityRenderer(
m: HistoryEntry,
wsProjects: ProjectBase[],
): string {
const renderer = fieldRenderers[m.field];

if (renderer) {
const result = renderer(m, wsProjects);
if (result) return result;
}

return renderDefault(m);
}

export { getIcon } from './utils/getIcon';

export type { HistoryEntry, HistoryRenderer } from './types';

Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
interface ActionTranslation {
add: string;
remove: string;
}

export const HISTORY_ACTIONS: Record<string, ActionTranslation> = {
blocks: {
add: 'добавил(-а)',
remove: 'удалил(-а)',
},
assignees: {
add: 'добавил(-а)',
remove: 'убрал(-а)',
},
watchers: {
add: 'добавил(-а)',
remove: 'убрал(-а)',
},
labels: {
add: 'добавил(-а) тег',
remove: 'удалил(-а) тег',
},
label: {
add: 'добавил(-а) тег',
remove: 'удалил(-а) тег',
},
linked: {
add: 'добавил(-а) связь с задачей',
remove: 'убрал(-а) связь с задачей',
},
sub_issue: {
add: 'добавил(-а) подзадачу',
remove: 'удалил(-а) подзадачу',
},
parent: {
add: 'заблокировал(-а) задачу',
remove: 'снял(-а)',
},
blocking: {
add: 'заблокировал(-а) задачу',
remove: 'снял(-а)',
},
link: {
add: 'добавил(-а) ссылку',
remove: 'удалил(-а) ссылку',
},
attachment: {
add: 'добавил(-а)',
remove: 'удалил(-а)',
},
doc: {
add: 'добавил(-а) вложенный документ',
remove: 'убрал(-а) вложенный документ',
},
sprint: {
add: 'добавил(-а) спринт',
remove: 'убрал(-а) спринт',
},
};

export function translateHistoryAction(field: string, isAdd: boolean): string {
const actions = HISTORY_ACTIONS[field] || HISTORY_ACTIONS.blocks;
return isAdd ? actions.add : actions.remove;
}

24 changes: 24 additions & 0 deletions src/components/activity/entityActivity/renders/assignees.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { HistoryEntry } from '../types';
import aiplan from 'src/utils/aiplan';
import { translateHistoryAction } from './actionTranslations';

export function renderAssignees(m: HistoryEntry): string {
if (m.old_value == null || m.old_value === '') {
return `${translateHistoryAction('assignees', true)} ${aiplan.ru_field(m)} ${aiplan.UserName(m.new_entity_detail).join(' ')}`;
}
if (m.new_value === '') {
return `${translateHistoryAction('assignees', false)} ${aiplan.ru_field(m)} ${aiplan.UserName(m.old_entity_detail).join(' ')}`;
}
return `${aiplan.ru_verb(m)} ${aiplan.ru_field(m)} ${aiplan.ru_value(m)}`;
}

export function renderWatchers(m: HistoryEntry): string {
if (m.old_value == null || m.old_value === '') {
return `${translateHistoryAction('watchers', true)} ${aiplan.ru_field(m)} ${aiplan.UserName(m.new_entity_detail).join(' ')}`;
}
if (m.new_value === '') {
return `${translateHistoryAction('watchers', false)} ${aiplan.ru_field(m)} ${aiplan.UserName(m.old_entity_detail).join(' ')}`;
}
return `${aiplan.ru_verb(m)} ${aiplan.ru_field(m)} ${aiplan.ru_value(m)}`;
}

11 changes: 11 additions & 0 deletions src/components/activity/entityActivity/renders/attachments.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { HistoryEntry } from '../types';
import aiplan from 'src/utils/aiplan';
import { translateHistoryAction } from './actionTranslations';

export function renderAttachment(m: HistoryEntry): string {
if (m.verb === 'created') {
return `${translateHistoryAction('attachment', true)} ${aiplan.ru_field(m)} ${aiplan.ru_value(m)} "${m.new_entity_detail?.asset.name || m.new_value}"`;
}
return `${aiplan.ru_verb(m)} ${aiplan.ru_field(m)} ${aiplan.ru_value(m)} "${m.old_value}"`;
}

14 changes: 14 additions & 0 deletions src/components/activity/entityActivity/renders/blocks.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { HistoryEntry } from '../types';
import aiplan from 'src/utils/aiplan';
import { translateHistoryAction } from './actionTranslations';

export function renderBlocks(m: HistoryEntry): string {
if (m.old_value == null || m.old_value === '') {
return `${translateHistoryAction('blocks', true)} ${aiplan.ru_field(m)} ${m.new_value}`;
}
if (m.new_value === '') {
return `${translateHistoryAction('blocks', false)} ${aiplan.ru_field(m)} ${m.old_value}`;
}
return `${aiplan.ru_verb(m)} ${aiplan.ru_field(m)} ${aiplan.ru_value(m)}`;
}

10 changes: 10 additions & 0 deletions src/components/activity/entityActivity/renders/comments.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { HistoryEntry } from '../types';
import aiplan from 'src/utils/aiplan';

export function renderComment(m: HistoryEntry): string {
if (m.verb === 'created') {
return `добавил(-а) ${aiplan.ru_field(m)} ${aiplan.ru_value(m)}`;
}
return `${aiplan.ru_verb(m)} ${aiplan.ru_field(m)} ${aiplan.ru_value(m)}`;
}

37 changes: 37 additions & 0 deletions src/components/activity/entityActivity/renders/dates.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import { HistoryEntry } from '../types';
import { formatDate } from 'src/utils/time';
import { canBeConvertedToDate } from 'src/utils/canBeConvertedToDate';

export function renderCompletedAt(): string {
return 'завершил(-а) задачу';
}

export function renderStartDate(): string {
return 'начал(-а) выполнение задачи';
}

export function renderTargetDate(m: HistoryEntry): string | undefined {
if (m.verb !== 'updated') {
return undefined;
}

const newDate =
m.new_value && canBeConvertedToDate(m.new_value)
? formatDate(m.new_value)
: '';
const oldDate =
m.old_value && canBeConvertedToDate(m.old_value)
? formatDate(m.old_value.replace(/"/g, ''))
: '';

if (m.old_value === '<nil>' || !m.old_value) {
return `установил(-а) срок исполнения ${newDate}`;
} else if (m.new_value === '' && oldDate) {
return `убрал(-а) срок исполнения ${oldDate}`;
} else {
return oldDate && newDate
? `изменил(-а) срок исполнения с ${oldDate} на ${newDate}`
: 'изменил(-а) срок исполнения';
}
}

40 changes: 40 additions & 0 deletions src/components/activity/entityActivity/renders/docs.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import { HistoryEntry } from '../types';
import { translateHistoryAction } from './actionTranslations';

export function renderDoc(m: HistoryEntry): string | undefined {
if (m.verb === 'remove') {
return `${translateHistoryAction('doc', false)} "${m.old_value}"`;
}
if (m.verb === 'added') {
return `${translateHistoryAction('doc', true)} "${m.new_value}"`;
}
if (m.verb === 'created') {
return `создал(-а) вложенный документ "${m.new_value}"`;
}
return undefined;
}

export function renderSeqId(m: HistoryEntry): string | undefined {
if (m.verb === 'updated') {
return `изменил(-а) позицию документа в директории с ${+m.old_value! + 1} на ${+m.new_value! + 1}`;
}
if (m.verb === 'move') {
if (m.new_value === m.workspace_detail?.name) {
return 'перенес(-ла) документ в корневую директорию';
} else {
return `перенес(-ла) документ в директорию "${m.new_value}"`;
}
}
return undefined;
}

export function renderDescription(m: HistoryEntry): string | undefined {
if (m.verb === 'updated') {
return 'изменил(-а) описание';
}
if (m.entity_type === 'doc') {
return 'изменил(-а) описание';
}
return undefined;
}

34 changes: 34 additions & 0 deletions src/components/activity/entityActivity/renders/issues.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { HistoryEntry } from '../types';
import aiplan from 'src/utils/aiplan';
import { translateHistoryAction } from './actionTranslations';

export function renderParent(m: HistoryEntry): string {
if (m.old_value == null || m.old_value === '') {
return `${aiplan.UserName(m.target_user).join(' ')} ${translateHistoryAction('parent', true)} ${m.new_value}`;
}
if (m.new_value === '') {
return `${aiplan.UserName(m.target_user).join(' ')} ${translateHistoryAction('parent', false)} ${aiplan.ru_field(m)} с задачи ${m.old_value}`;
}
return `${aiplan.ru_verb(m)} ${aiplan.ru_field(m)} ${aiplan.ru_value(m)}`;
}

export function renderBlocking(m: HistoryEntry): string {
if (m.old_value == null || m.old_value === '') {
return `${aiplan.UserName(m.target_user).join(' ')} ${translateHistoryAction('blocking', true)} ${m.new_value}`;
}
if (m.new_value === '') {
return `${aiplan.UserName(m.target_user).join(' ')} ${translateHistoryAction('blocking', false)} ${aiplan.ru_field(m)} с задачи ${m.old_value}`;
}
return `${aiplan.ru_verb(m)} ${aiplan.ru_field(m)} ${aiplan.ru_value(m)}`;
}

export function renderSubIssue(m: HistoryEntry): string | undefined {
if (m.verb === 'added') {
return `${translateHistoryAction('sub_issue', true)} ${m.new_value}`;
}
if (m.verb === 'removed') {
return `${translateHistoryAction('sub_issue', false)} ${m.old_value}`;
}
return undefined;
}

23 changes: 23 additions & 0 deletions src/components/activity/entityActivity/renders/labels.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { HistoryEntry } from '../types';
import { translateHistoryAction } from './actionTranslations';

export function renderLabels(m: HistoryEntry): string | undefined {
if (m.verb === 'added') {
return `${translateHistoryAction('labels', true)} ${m.new_value}`;
}
if (m.verb === 'removed') {
return `${translateHistoryAction('labels', false)} ${m.old_value}`;
}
return undefined;
}

export function renderLabel(m: HistoryEntry): string | undefined {
if (m.verb === 'added') {
return `${translateHistoryAction('label', true)} ${m.new_value}`;
}
if (m.verb === 'removed') {
return `${translateHistoryAction('label', false)} ${m.old_value}`;
}
return undefined;
}

Loading