Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added log autoscroll #2017

Draft
wants to merge 4 commits into
base: master
Choose a base branch
from
Draft
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
12 changes: 11 additions & 1 deletion src/components/cylc/log/Log.vue
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
v-for="(log, index) in computedLogs"
:key="index"
:class="wordWrap ? 'text-pre-wrap' : 'text-pre'"
>{{ log }}</span></pre>
>{{ log }}</span>
</pre>
</template>

<script>
Expand Down Expand Up @@ -84,6 +85,15 @@ export default {
}
return logLine
}
},

watch: {
computedLogs: {
handler (val, old) {
this.$emit('updating')
},
deep: true
}
}
}

Expand Down
27 changes: 26 additions & 1 deletion src/views/Log.vue
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,10 @@
:logs="results.lines"
:timestamps="timestamps"
:word-wrap="wordWrap"
@updating="updating"
/>
<!-- a div to use for autoscrolling -->
<div class="auto-scroll-end"></div>
</template>
</v-col>
</v-row>
Expand All @@ -188,6 +191,7 @@
mdiPowerPlugOff,
mdiPowerPlug,
mdiWrap,
mdiMouseScrollWheel,
} from '@mdi/js'
import { btnProps } from '@/utils/viewToolbar'
import graphqlMixin from '@/mixins/graphql'
Expand Down Expand Up @@ -411,6 +415,7 @@

data () {
return {
autoScroll: false,
controlGroups: [
{
title: 'Log',
Expand All @@ -429,6 +434,13 @@
value: this.wordWrap,
key: 'wordWrap',
},
{
title: 'Auto scroll',
icon: mdiMouseScrollWheel,
action: 'toggle',
value: this.autoScroll,
key: 'autoScroll',
},
]
}
],
Expand Down Expand Up @@ -478,6 +490,19 @@
},

methods: {
scrollToElement (elementCLassName, options) {
const el = this.$el.getElementsByClassName(elementCLassName)[0]

Check warning on line 494 in src/views/Log.vue

View check run for this annotation

Codecov / codecov/patch

src/views/Log.vue#L494

Added line #L494 was not covered by tests

if (el) {
// Use el.scrollIntoView() to instantly scroll to the element
el.scrollIntoView(options)

Check warning on line 498 in src/views/Log.vue

View check run for this annotation

Codecov / codecov/patch

src/views/Log.vue#L498

Added line #L498 was not covered by tests
}
},
updating () {
if (this.autoScroll) {
this.scrollToElement('auto-scroll-end', { behavior: 'smooth' })

Check warning on line 503 in src/views/Log.vue

View check run for this annotation

Codecov / codecov/patch

src/views/Log.vue#L503

Added line #L503 was not covered by tests
}
},
setOption (option, value) {
// used by the ViewToolbar to update settings
this[option] = value
Expand Down Expand Up @@ -568,7 +593,7 @@
this.file = null
// go back to last chosen job if we are switching back to job logs
this.relativeID = val ? this.previousRelativeID : null
},
}
},

// Misc options
Expand Down
4 changes: 2 additions & 2 deletions tests/e2e/specs/log.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ describe('Log View', () => {
.click()
// the old log file lines should have been wiped
.get('[data-cy=log-viewer]')
.should('be.empty')
.should('have.length', 1)
.get('[data-cy=file-input] input')
.should('be.disabled')

Expand All @@ -130,7 +130,7 @@ describe('Log View', () => {
.find('input')
.type('1/')
.get('[data-cy=log-viewer]')
.should('be.empty')
.should('have.length', 1)
.get('[data-cy=file-input] input')
.should('be.disabled')

Expand Down
Loading