mirror of
https://github.com/woodpecker-ci/woodpecker.git
synced 2024-06-02 13:39:55 +00:00
58838f225c
Rewrite of the UI using Typescript, Vue3, Windicss and Vite. The design should be close to the current one with some changes: - latest pipeline in a sidebar on the right - secrets and registry as part of the repo-settings (secrets and registry entries shouldn't be used as much so they can be "hidden" under settings IMO) - start page shows list of active repositories with button to enable / add new ones (currently you see all repositories and in most cases you only add new repositories once in a while)
85 lines
1.9 KiB
TypeScript
85 lines
1.9 KiB
TypeScript
import { computed, Ref } from 'vue';
|
|
|
|
import { useElapsedTime } from '~/compositions/useElapsedTime';
|
|
import { Build } from '~/lib/api/types';
|
|
import { prettyDuration } from '~/utils/duration';
|
|
import { convertEmojis } from '~/utils/emoji';
|
|
import timeAgo from '~/utils/timeAgo';
|
|
|
|
export default (build: Ref<Build | undefined>) => {
|
|
const sinceRaw = computed(() => {
|
|
if (!build.value) {
|
|
return undefined;
|
|
}
|
|
|
|
const start = build.value.started_at || 0;
|
|
|
|
if (start === 0) {
|
|
return 0;
|
|
}
|
|
|
|
return start * 1000;
|
|
});
|
|
|
|
const sinceUnderOneHour = computed(
|
|
() => sinceRaw.value !== undefined && sinceRaw.value > 0 && sinceRaw.value <= 1000 * 60 * 60,
|
|
);
|
|
const { time: sinceElapsed } = useElapsedTime(sinceUnderOneHour, sinceRaw);
|
|
|
|
const since = computed(() => {
|
|
if (sinceRaw.value === 0) {
|
|
return 'not started yet';
|
|
}
|
|
|
|
if (sinceElapsed.value === undefined) {
|
|
return null;
|
|
}
|
|
|
|
return timeAgo.format(sinceElapsed.value);
|
|
});
|
|
|
|
const durationRaw = computed(() => {
|
|
if (!build.value) {
|
|
return undefined;
|
|
}
|
|
|
|
const start = build.value.started_at || 0;
|
|
const end = build.value.finished_at || 0;
|
|
|
|
if (start === 0) {
|
|
return 0;
|
|
}
|
|
|
|
if (end === 0) {
|
|
return Date.now() - start * 1000;
|
|
}
|
|
|
|
return (end - start) * 1000;
|
|
});
|
|
|
|
const running = computed(() => build.value !== undefined && build.value.status === 'running');
|
|
const { time: durationElapsed } = useElapsedTime(running, durationRaw);
|
|
|
|
const duration = computed(() => {
|
|
if (durationElapsed.value === undefined) {
|
|
return null;
|
|
}
|
|
|
|
if (durationRaw.value === 0) {
|
|
return 'not started yet';
|
|
}
|
|
|
|
return prettyDuration(durationElapsed.value);
|
|
});
|
|
|
|
const message = computed(() => {
|
|
if (!build.value) {
|
|
return '';
|
|
}
|
|
|
|
return convertEmojis(build.value.message);
|
|
});
|
|
|
|
return { since, duration, message };
|
|
};
|