Skip to content

Commit 3e84b65

Browse files
committed
add options
1 parent 3aa5441 commit 3e84b65

File tree

3 files changed

+39
-16
lines changed

3 files changed

+39
-16
lines changed

options/locale/locale_en-US.ini

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3773,8 +3773,8 @@ variables.creation.success = The variable "%s" has been added.
37733773
variables.update.failed = Failed to edit variable.
37743774
variables.update.success = The variable has been edited.
37753775

3776-
logs.always_auto_scroll = Always auto scroll
3777-
logs.always_auto_expand = Always auto expand
3776+
logs.always_auto_scroll = Always auto scroll logs
3777+
logs.always_expand_running = Always expand running logs
37783778

37793779
[projects]
37803780
deleted.display_name = Deleted Project

templates/repo/actions/view_component.tmpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,6 @@
2525
data-locale-show-full-screen="{{ctx.Locale.Tr "show_full_screen"}}"
2626
data-locale-download-logs="{{ctx.Locale.Tr "download_logs"}}"
2727
data-locale-logs-always-auto-scroll="{{ctx.Locale.Tr "actions.logs.always_auto_scroll"}}"
28-
data-locale-logs-always-auto-expand="{{ctx.Locale.Tr "actions.logs.always_auto_expand"}}"
28+
data-locale-logs-always-expand-running="{{ctx.Locale.Tr "actions.logs.always_expand_running"}}"
2929
>
3030
</div>

web_src/js/components/RepoActionView.vue

Lines changed: 36 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,17 @@ function isLogElementInViewport(el: HTMLElement): boolean {
4343
return rect.top >= 0 && rect.bottom <= window.innerHeight; // only check height but not width
4444
}
4545
46+
type LocaleStorageOptions = {
47+
autoScroll: boolean;
48+
expandRunning: boolean;
49+
};
50+
51+
function getLocaleStorageOptions(): LocaleStorageOptions {
52+
const optsJson = localStorage.getItem('actions-view-options');
53+
if (optsJson) return JSON.parse(optsJson);
54+
return {autoScroll: true, expandRunning: false};
55+
}
56+
4657
const sfc = {
4758
name: 'RepoActionView',
4859
components: {
@@ -56,7 +67,17 @@ const sfc = {
5667
locale: Object,
5768
},
5869
70+
watch: {
71+
optionAlwaysAutoScroll() {
72+
this.saveLocaleStorageOptions();
73+
},
74+
optionAlwaysExpandRunning() {
75+
this.saveLocaleStorageOptions();
76+
},
77+
},
78+
5979
data() {
80+
const {autoScroll, expandRunning} = getLocaleStorageOptions();
6081
return {
6182
// internal state
6283
loadingAbortController: null,
@@ -70,8 +91,8 @@ const sfc = {
7091
'log-time-stamp': false,
7192
'log-time-seconds': false,
7293
},
73-
optionAlwaysAutoExpand: false,
74-
optionAlwaysAutoScroll: false,
94+
optionAlwaysAutoScroll: autoScroll ?? false,
95+
optionAlwaysExpandRunning: expandRunning ?? false,
7596
7697
// provided by backend
7798
run: {
@@ -149,6 +170,11 @@ const sfc = {
149170
},
150171
151172
methods: {
173+
saveLocaleStorageOptions() {
174+
const opts: LocaleStorageOptions = {autoScroll: this.optionAlwaysAutoScroll, expandRunning: this.optionAlwaysExpandRunning};
175+
localStorage.setItem('actions-view-options', JSON.stringify(opts));
176+
},
177+
152178
// get the job step logs container ('.job-step-logs')
153179
getJobStepLogsContainer(stepIndex: number): HTMLElement {
154180
return this.$refs.logs[stepIndex];
@@ -230,6 +256,7 @@ const sfc = {
230256
},
231257
232258
shouldAutoScroll(stepIndex: number): boolean {
259+
if (!this.optionAlwaysAutoScroll) return false;
233260
const el = this.getJobStepLogsContainer(stepIndex);
234261
if (!el.lastChild) return false;
235262
return isLogElementInViewport(el.lastChild);
@@ -282,6 +309,7 @@ const sfc = {
282309
const abortController = new AbortController();
283310
this.loadingAbortController = abortController;
284311
try {
312+
const isFirstLoad = !this.run.status;
285313
const job = await this.fetchJobData(abortController);
286314
if (this.loadingAbortController !== abortController) return;
287315
@@ -291,15 +319,10 @@ const sfc = {
291319
292320
// sync the currentJobStepsStates to store the job step states
293321
for (let i = 0; i < this.currentJob.steps.length; i++) {
322+
const expanded = isFirstLoad && this.optionAlwaysExpandRunning && this.currentJob.steps[i].status === 'running';
294323
if (!this.currentJobStepsStates[i]) {
295324
// initial states for job steps
296-
this.currentJobStepsStates[i] = {cursor: null, expanded: false};
297-
}
298-
299-
// expands the currently running job step if its state wasn't 'running' before
300-
if (this.currentJob.steps[i].status === 'running' && this.currentJobStepsStates[i].cursor === null) {
301-
this.currentJobStepsStates[i].cursor = 0;
302-
this.currentJobStepsStates[i].expanded = true;
325+
this.currentJobStepsStates[i] = {cursor: null, expanded};
303326
}
304327
}
305328
@@ -435,7 +458,7 @@ export function initRepositoryActionView() {
435458
blocked: el.getAttribute('data-locale-status-blocked'),
436459
},
437460
logsAlwaysAutoScroll: el.getAttribute('data-locale-logs-always-auto-scroll'),
438-
logsAlwaysAutoExpand: el.getAttribute('data-locale-logs-always-auto-expand'),
461+
logsAlwaysExpandRunning: el.getAttribute('data-locale-logs-always-expand-running'),
439462
},
440463
});
441464
view.mount(el);
@@ -544,9 +567,9 @@ export function initRepositoryActionView() {
544567
<i class="icon"><SvgIcon :name="optionAlwaysAutoScroll ? 'octicon-check' : 'gitea-empty-checkbox'"/></i>
545568
{{ locale.logsAlwaysAutoScroll }}
546569
</a>
547-
<a class="item" @click="optionAlwaysAutoExpand = !optionAlwaysAutoExpand">
548-
<i class="icon"><SvgIcon :name="optionAlwaysAutoExpand ? 'octicon-check' : 'gitea-empty-checkbox'"/></i>
549-
{{ locale.logsAlwaysAutoExpand }}
570+
<a class="item" @click="optionAlwaysExpandRunning = !optionAlwaysExpandRunning">
571+
<i class="icon"><SvgIcon :name="optionAlwaysExpandRunning ? 'octicon-check' : 'gitea-empty-checkbox'"/></i>
572+
{{ locale.logsAlwaysExpandRunning }}
550573
</a>
551574

552575
<div class="divider"/>

0 commit comments

Comments
 (0)