Skip to content

Commit a7799d5

Browse files
committed
[WHIP] Updates
Signed-off-by: Christopher Ng <chrng8@gmail.com>
1 parent 66ad22f commit a7799d5

14 files changed

Lines changed: 456 additions & 82 deletions

File tree

apps/settings/css/settings.scss

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ input {
114114
.profile-settings-container {
115115
display: inline-grid;
116116
grid-template-columns: 1fr;
117-
grid-template-rows: 1fr 1fr 2fr;
117+
grid-template-rows: 1fr 1fr 1fr 2fr;
118118

119119
#locale {
120120
h3 {
@@ -223,7 +223,7 @@ select {
223223

224224
.personal-settings-container {
225225
grid-template-columns: 1fr 1fr;
226-
grid-template-rows: 1fr 1fr 1fr;
226+
grid-template-rows: 1fr 1fr 1fr 1fr;
227227
}
228228

229229
.profile-settings-container {
@@ -245,7 +245,7 @@ select {
245245

246246
.personal-settings-container {
247247
grid-template-columns: 1fr 1fr;
248-
grid-template-rows: 1fr 1fr 1fr;
248+
grid-template-rows: 1fr 1fr 1fr 1fr;
249249
}
250250

251251
.profile-settings-container {
@@ -279,7 +279,7 @@ select {
279279
.personal-settings-container {
280280
display: inline-grid;
281281
grid-template-columns: 1fr 1fr;
282-
grid-template-rows: 1fr 1fr 2fr;
282+
grid-template-rows: 1fr 1fr 1fr 2fr;
283283

284284
&:after {
285285
clear: both;

apps/settings/lib/Settings/Personal/PersonalInfo.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,7 @@ public function getForm(): TemplateResponse {
151151
'emails' => $this->getEmails($account),
152152
'languages' => $this->getLanguages($user),
153153
'profileEnabled' => $this->getProfileEnabled($account),
154+
'companies' => $this->getCompanies($account),
154155
];
155156

156157
$accountParameters = [
@@ -164,6 +165,29 @@ public function getForm(): TemplateResponse {
164165
return new TemplateResponse('settings', 'settings/personal/personal.info', $parameters, '');
165166
}
166167

168+
/**
169+
* returns the primary display name in an
170+
* associative array
171+
*
172+
* NOTE may be extended to provide additional companies in the future
173+
*
174+
* @param IAccount $account
175+
* @return array
176+
*/
177+
private function getCompanies(IAccount $account): array {
178+
$primaryCompany = [
179+
'value' => $account->getProperty(IAccountManager::PROPERTY_COMPANY)->getValue(),
180+
'scope' => $account->getProperty(IAccountManager::PROPERTY_COMPANY)->getScope(),
181+
'verified' => $account->getProperty(IAccountManager::PROPERTY_COMPANY)->getVerified(),
182+
];
183+
184+
$companies = [
185+
'primaryCompany' => $primaryCompany,
186+
];
187+
188+
return $companies;
189+
}
190+
167191
/**
168192
* @return string the section ID, e.g. 'sharing'
169193
* @since 9.1
Lines changed: 178 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,178 @@
1+
<!--
2+
- @copyright 2021, Christopher Ng <chrng8@gmail.com>
3+
-
4+
- @author Christopher Ng <chrng8@gmail.com>
5+
-
6+
- @license GNU AGPL version 3 or any later version
7+
-
8+
- This program is free software: you can redistribute it and/or modify
9+
- it under the terms of the GNU Affero General Public License as
10+
- published by the Free Software Foundation, either version 3 of the
11+
- License, or (at your option) any later version.
12+
-
13+
- This program is distributed in the hope that it will be useful,
14+
- but WITHOUT ANY WARRANTY; without even the implied warranty of
15+
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16+
- GNU Affero General Public License for more details.
17+
-
18+
- You should have received a copy of the GNU Affero General Public License
19+
- along with this program. If not, see <http://www.gnu.org/licenses/>.
20+
-->
21+
22+
<template>
23+
<div class="company">
24+
<input
25+
id="company"
26+
type="text"
27+
name="company"
28+
:placeholder="t('settings', 'Your company')"
29+
:value="company"
30+
autocapitalize="none"
31+
autocomplete="on"
32+
autocorrect="off"
33+
required
34+
@input="onCompanyChange">
35+
36+
<div class="company__actions-container">
37+
<transition name="fade">
38+
<span v-if="showCheckmarkIcon" class="icon-checkmark" />
39+
<span v-else-if="showErrorIcon" class="icon-error" />
40+
</transition>
41+
</div>
42+
</div>
43+
</template>
44+
45+
<script>
46+
import { showError } from '@nextcloud/dialogs'
47+
import { emit } from '@nextcloud/event-bus'
48+
import debounce from 'debounce'
49+
50+
// import { savePrimaryCompany } from '../../../service/PersonalInfo/DisplayNameService'
51+
// import { validateCompany } from '../../../utils/validate'
52+
53+
export default {
54+
name: 'Company',
55+
56+
props: {
57+
company: {
58+
type: String,
59+
required: true,
60+
},
61+
scope: {
62+
type: String,
63+
required: true,
64+
},
65+
},
66+
67+
data() {
68+
return {
69+
initialCompany: this.company,
70+
localScope: this.scope,
71+
showCheckmarkIcon: false,
72+
showErrorIcon: false,
73+
}
74+
},
75+
76+
methods: {
77+
onCompanyChange(e) {
78+
this.$emit('update:company', e.target.value)
79+
this.debounceCompanyChange(e.target.value.trim())
80+
},
81+
82+
debounceCompanyChange: debounce(async function(company) {
83+
if (validateCompany(company)) {
84+
await this.updatePrimaryCompany(company)
85+
}
86+
}, 500),
87+
88+
async updatePrimaryCompany(company) {
89+
try {
90+
const responseData = await savePrimaryCompany(company)
91+
this.handleResponse({
92+
company,
93+
status: responseData.ocs?.meta?.status,
94+
})
95+
} catch (e) {
96+
this.handleResponse({
97+
errorMessage: 'Unable to update full name',
98+
error: e,
99+
})
100+
}
101+
},
102+
103+
handleResponse({ company, status, errorMessage, error }) {
104+
if (status === 'ok') {
105+
// Ensure that local state reflects server state
106+
this.initialCompany = company
107+
emit('settings:display-name:updated', company)
108+
this.showCheckmarkIcon = true
109+
setTimeout(() => { this.showCheckmarkIcon = false }, 2000)
110+
} else {
111+
showError(t('settings', errorMessage))
112+
this.logger.error(errorMessage, error)
113+
this.showErrorIcon = true
114+
setTimeout(() => { this.showErrorIcon = false }, 2000)
115+
}
116+
},
117+
118+
onScopeChange(scope) {
119+
this.$emit('update:scope', scope)
120+
},
121+
},
122+
}
123+
</script>
124+
125+
<style lang="scss" scoped>
126+
.company {
127+
display: grid;
128+
align-items: center;
129+
130+
input {
131+
grid-area: 1 / 1;
132+
width: 100%;
133+
height: 34px;
134+
margin: 3px 3px 3px 0;
135+
padding: 7px 6px;
136+
color: var(--color-main-text);
137+
border: 1px solid var(--color-border-dark);
138+
border-radius: var(--border-radius);
139+
background-color: var(--color-main-background);
140+
font-family: var(--font-face);
141+
cursor: text;
142+
}
143+
144+
.company__actions-container {
145+
grid-area: 1 / 1;
146+
justify-self: flex-end;
147+
height: 30px;
148+
149+
display: flex;
150+
gap: 0 2px;
151+
margin-right: 5px;
152+
153+
.icon-checkmark,
154+
.icon-error {
155+
height: 30px !important;
156+
min-height: 30px !important;
157+
width: 30px !important;
158+
min-width: 30px !important;
159+
top: 0;
160+
right: 0;
161+
float: none;
162+
}
163+
}
164+
}
165+
166+
.fade-enter,
167+
.fade-leave-to {
168+
opacity: 0;
169+
}
170+
171+
.fade-enter-active {
172+
transition: opacity 200ms ease-out;
173+
}
174+
175+
.fade-leave-active {
176+
transition: opacity 300ms ease-out;
177+
}
178+
</style>
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
<!--
2+
- @copyright 2021, Christopher Ng <chrng8@gmail.com>
3+
-
4+
- @author Christopher Ng <chrng8@gmail.com>
5+
-
6+
- @license GNU AGPL version 3 or any later version
7+
-
8+
- This program is free software: you can redistribute it and/or modify
9+
- it under the terms of the GNU Affero General Public License as
10+
- published by the Free Software Foundation, either version 3 of the
11+
- License, or (at your option) any later version.
12+
-
13+
- This program is distributed in the hope that it will be useful,
14+
- but WITHOUT ANY WARRANTY; without even the implied warranty of
15+
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16+
- GNU Affero General Public License for more details.
17+
-
18+
- You should have received a copy of the GNU Affero General Public License
19+
- along with this program. If not, see <http://www.gnu.org/licenses/>.
20+
-->
21+
22+
<template>
23+
<section>
24+
<HeaderBar
25+
:account-property="accountProperty"
26+
label-for="company"
27+
:is-editable="companyChangeSupported"
28+
:is-valid-section="isValidSection"
29+
:handle-scope-change="savePrimaryCompanyScope"
30+
:scope.sync="primaryCompany.scope" />
31+
32+
<Company
33+
:company.sync="primaryCompany.value"
34+
:scope.sync="primaryCompany.scope" />
35+
</section>
36+
</template>
37+
38+
<script>
39+
import { loadState } from '@nextcloud/initial-state'
40+
41+
import Company from './Company'
42+
import HeaderBar from '../shared/HeaderBar'
43+
44+
import { ACCOUNT_PROPERTY_READABLE_ENUM } from '../../../constants/AccountPropertyConstants'
45+
// import { savePrimaryCompanyScope } from '../../../service/PersonalInfo/CompanyService'
46+
// import { validateCompany } from '../../../utils/validate'
47+
48+
console.log(loadState('settings', 'personalInfoParameters', {}))
49+
const { companies: { primaryCompany } } = loadState('settings', 'personalInfoParameters', {})
50+
51+
export default {
52+
name: 'CompanySection',
53+
54+
components: {
55+
Company,
56+
HeaderBar,
57+
},
58+
59+
data() {
60+
return {
61+
accountProperty: ACCOUNT_PROPERTY_READABLE_ENUM.COMPANY,
62+
primaryCompany,
63+
// savePrimaryCompanyScope,
64+
}
65+
},
66+
67+
computed: {
68+
isValidSection() {
69+
// return validateCompany(this.primaryCompany.value)
70+
},
71+
},
72+
}
73+
</script>
74+
75+
<style lang="scss" scoped>
76+
section {
77+
padding: 10px 10px;
78+
79+
&::v-deep button:disabled {
80+
cursor: default;
81+
}
82+
}
83+
</style>

apps/settings/src/components/PersonalInfo/DisplayNameSection/DisplayName.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ export default {
107107
if (status === 'ok') {
108108
// Ensure that local state reflects server state
109109
this.initialDisplayName = displayName
110-
emit('settings:displayName:updated', displayName)
110+
emit('settings:display-name:updated', displayName)
111111
this.showCheckmarkIcon = true
112112
setTimeout(() => { this.showCheckmarkIcon = false }, 2000)
113113
} else {

apps/settings/src/components/PersonalInfo/ProfileSection/ProfileCheckbox.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ export default {
8888
if (status === 'ok') {
8989
// Ensure that local state reflects server state
9090
this.initialProfileEnabled = isEnabled
91-
emit('settings:profileEnabled:updated', isEnabled)
91+
emit('settings:profile-enabled:updated', isEnabled)
9292
this.showCheckmarkIcon = true
9393
setTimeout(() => { this.showCheckmarkIcon = false }, 2000)
9494
} else {

apps/settings/src/main-personal-info.js

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ import DisplayNameSection from './components/PersonalInfo/DisplayNameSection/Dis
3131
import EmailSection from './components/PersonalInfo/EmailSection/EmailSection'
3232
import LanguageSection from './components/PersonalInfo/LanguageSection/LanguageSection'
3333
import ProfileSection from './components/PersonalInfo/ProfileSection/ProfileSection'
34+
import CompanySection from './components/PersonalInfo/CompanySection/CompanySection'
3435

3536
__webpack_nonce__ = btoa(getRequestToken())
3637

@@ -47,8 +48,10 @@ const DisplayNameView = Vue.extend(DisplayNameSection)
4748
const EmailView = Vue.extend(EmailSection)
4849
const LanguageView = Vue.extend(LanguageSection)
4950
const ProfileView = Vue.extend(ProfileSection)
51+
const CompanyView = Vue.extend(CompanySection)
5052

51-
new DisplayNameView().$mount('#vue-displaynamesection')
52-
new EmailView().$mount('#vue-emailsection')
53-
new LanguageView().$mount('#vue-languagesection')
54-
new ProfileView().$mount('#vue-profilesection')
53+
new DisplayNameView().$mount('#vue-displayname-section')
54+
new EmailView().$mount('#vue-email-section')
55+
new LanguageView().$mount('#vue-language-section')
56+
new ProfileView().$mount('#vue-profile-section')
57+
new CompanyView().$mount('#vue-company-section')

0 commit comments

Comments
 (0)