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

Update window title #368

Merged
merged 1 commit into from
May 9, 2020
Merged
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
32 changes: 32 additions & 0 deletions src/mixins/WindowTitleMixin.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/**
* @copyright Copyright (c) 2020 Jonas Rittershofer <jotoeri@users.noreply.github.com>
*
* @author Jonas Rittershofer <jotoeri@users.noreply.github.com>
*
* @license GNU AGPL version 3 or any later version
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

export default {
methods: {
setWindowTitle(formTitle) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I would prefer this as a function to import, rather than a mixin. Because it really doesn't need the full component context :)
@jotoeri

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:D shit. I see, i should wait for two approvals even on small changes. 🤦‍♂️
I'll change it.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Usually we do aim for 2 in nextcloud, but there isn't too much devs here (3), so after release we could bump it to 2 to make sure ;)

if (formTitle === '') {
window.document.title = t('forms', 'Forms') + ' - ' + OC.theme.title
} else {
window.document.title = formTitle + ' - ' + t('forms', 'Forms') + ' - ' + OC.theme.title
}
},
},
}
9 changes: 8 additions & 1 deletion src/views/Create.vue
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ import QuestionMultiple from '../components/Questions/QuestionMultiple'
import QuestionShort from '../components/Questions/QuestionShort'
import TopBar from '../components/TopBar'
import ViewsMixin from '../mixins/ViewsMixin'
import WindowTitleMixin from '../mixins/WindowTitleMixin'

window.axios = axios

Expand All @@ -154,7 +155,7 @@ export default {
TopBar,
},

mixins: [ViewsMixin],
mixins: [ViewsMixin, WindowTitleMixin],

data() {
return {
Expand Down Expand Up @@ -201,10 +202,16 @@ export default {
// TODO: cancel previous request if not done
this.fetchFullForm(this.form.id)
},

// Update Window-Title on title change
'form.title': function() {
this.setWindowTitle(this.form.title)
},
},

beforeMount() {
this.fetchFullForm(this.form.id)
this.setWindowTitle(this.form.title)
},

updated() {
Expand Down
4 changes: 3 additions & 1 deletion src/views/Results.vue
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ import EmptyContent from '../components/EmptyContent'
import Submission from '../components/Results/Submission'
import TopBar from '../components/TopBar'
import ViewsMixin from '../mixins/ViewsMixin'
import WindowTitleMixin from '../mixins/WindowTitleMixin'

Vue.use(Clipboard)

Expand All @@ -111,7 +112,7 @@ export default {
TopBar,
},

mixins: [ViewsMixin],
mixins: [ViewsMixin, WindowTitleMixin],

data() {
return {
Expand All @@ -129,6 +130,7 @@ export default {

beforeMount() {
this.loadFormResults()
this.setWindowTitle(this.form.title)
},

methods: {
Expand Down
7 changes: 7 additions & 0 deletions src/views/Submit.vue
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ import Question from '../components/Questions/Question'
import QuestionLong from '../components/Questions/QuestionLong'
import QuestionShort from '../components/Questions/QuestionShort'
import QuestionMultiple from '../components/Questions/QuestionMultiple'
import WindowTitleMixin from '../mixins/WindowTitleMixin'

export default {
name: 'Submit',
Expand All @@ -99,6 +100,8 @@ export default {
QuestionMultiple,
},

mixins: [WindowTitleMixin],

data() {
return {
form: loadState('forms', 'form'),
Expand Down Expand Up @@ -137,6 +140,10 @@ export default {
},
},

beforeMount() {
this.setWindowTitle(this.form.title)
},

methods: {
/**
* Submit the form after the browser validated it 🚀
Expand Down