Skip to content

Commit

Permalink
[WHIP] Updates
Browse files Browse the repository at this point in the history
Signed-off-by: Christopher Ng <chrng8@gmail.com>
  • Loading branch information
Pytal committed Sep 9, 2021
1 parent 66ad22f commit a7799d5
Show file tree
Hide file tree
Showing 14 changed files with 456 additions and 82 deletions.
8 changes: 4 additions & 4 deletions apps/settings/css/settings.scss
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ input {
.profile-settings-container {
display: inline-grid;
grid-template-columns: 1fr;
grid-template-rows: 1fr 1fr 2fr;
grid-template-rows: 1fr 1fr 1fr 2fr;

#locale {
h3 {
Expand Down Expand Up @@ -223,7 +223,7 @@ select {

.personal-settings-container {
grid-template-columns: 1fr 1fr;
grid-template-rows: 1fr 1fr 1fr;
grid-template-rows: 1fr 1fr 1fr 1fr;
}

.profile-settings-container {
Expand All @@ -245,7 +245,7 @@ select {

.personal-settings-container {
grid-template-columns: 1fr 1fr;
grid-template-rows: 1fr 1fr 1fr;
grid-template-rows: 1fr 1fr 1fr 1fr;
}

.profile-settings-container {
Expand Down Expand Up @@ -279,7 +279,7 @@ select {
.personal-settings-container {
display: inline-grid;
grid-template-columns: 1fr 1fr;
grid-template-rows: 1fr 1fr 2fr;
grid-template-rows: 1fr 1fr 1fr 2fr;

&:after {
clear: both;
Expand Down
24 changes: 24 additions & 0 deletions apps/settings/lib/Settings/Personal/PersonalInfo.php
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ public function getForm(): TemplateResponse {
'emails' => $this->getEmails($account),
'languages' => $this->getLanguages($user),
'profileEnabled' => $this->getProfileEnabled($account),
'companies' => $this->getCompanies($account),
];

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

/**
* returns the primary display name in an
* associative array
*
* NOTE may be extended to provide additional companies in the future
*
* @param IAccount $account
* @return array
*/
private function getCompanies(IAccount $account): array {
$primaryCompany = [
'value' => $account->getProperty(IAccountManager::PROPERTY_COMPANY)->getValue(),
'scope' => $account->getProperty(IAccountManager::PROPERTY_COMPANY)->getScope(),
'verified' => $account->getProperty(IAccountManager::PROPERTY_COMPANY)->getVerified(),
];

$companies = [
'primaryCompany' => $primaryCompany,
];

return $companies;
}

/**
* @return string the section ID, e.g. 'sharing'
* @since 9.1
Expand Down
178 changes: 178 additions & 0 deletions apps/settings/src/components/PersonalInfo/CompanySection/Company.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,178 @@
<!--
- @copyright 2021, Christopher Ng <chrng8@gmail.com>
-
- @author Christopher Ng <chrng8@gmail.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/>.
-->

<template>
<div class="company">
<input
id="company"
type="text"
name="company"
:placeholder="t('settings', 'Your company')"
:value="company"
autocapitalize="none"
autocomplete="on"
autocorrect="off"
required
@input="onCompanyChange">

<div class="company__actions-container">
<transition name="fade">
<span v-if="showCheckmarkIcon" class="icon-checkmark" />
<span v-else-if="showErrorIcon" class="icon-error" />
</transition>
</div>
</div>
</template>

<script>
import { showError } from '@nextcloud/dialogs'
import { emit } from '@nextcloud/event-bus'
import debounce from 'debounce'
// import { savePrimaryCompany } from '../../../service/PersonalInfo/DisplayNameService'
// import { validateCompany } from '../../../utils/validate'
export default {
name: 'Company',
props: {
company: {
type: String,
required: true,
},
scope: {
type: String,
required: true,
},
},
data() {
return {
initialCompany: this.company,
localScope: this.scope,
showCheckmarkIcon: false,
showErrorIcon: false,
}
},
methods: {
onCompanyChange(e) {
this.$emit('update:company', e.target.value)
this.debounceCompanyChange(e.target.value.trim())
},
debounceCompanyChange: debounce(async function(company) {
if (validateCompany(company)) {
await this.updatePrimaryCompany(company)
}
}, 500),
async updatePrimaryCompany(company) {
try {
const responseData = await savePrimaryCompany(company)
this.handleResponse({
company,
status: responseData.ocs?.meta?.status,
})
} catch (e) {
this.handleResponse({
errorMessage: 'Unable to update full name',
error: e,
})
}
},
handleResponse({ company, status, errorMessage, error }) {
if (status === 'ok') {
// Ensure that local state reflects server state
this.initialCompany = company
emit('settings:display-name:updated', company)
this.showCheckmarkIcon = true
setTimeout(() => { this.showCheckmarkIcon = false }, 2000)
} else {
showError(t('settings', errorMessage))
this.logger.error(errorMessage, error)
this.showErrorIcon = true
setTimeout(() => { this.showErrorIcon = false }, 2000)
}
},
onScopeChange(scope) {
this.$emit('update:scope', scope)
},
},
}
</script>
<style lang="scss" scoped>
.company {
display: grid;
align-items: center;
input {
grid-area: 1 / 1;
width: 100%;
height: 34px;
margin: 3px 3px 3px 0;
padding: 7px 6px;
color: var(--color-main-text);
border: 1px solid var(--color-border-dark);
border-radius: var(--border-radius);
background-color: var(--color-main-background);
font-family: var(--font-face);
cursor: text;
}
.company__actions-container {
grid-area: 1 / 1;
justify-self: flex-end;
height: 30px;
display: flex;
gap: 0 2px;
margin-right: 5px;
.icon-checkmark,
.icon-error {
height: 30px !important;
min-height: 30px !important;
width: 30px !important;
min-width: 30px !important;
top: 0;
right: 0;
float: none;
}
}
}
.fade-enter,
.fade-leave-to {
opacity: 0;
}
.fade-enter-active {
transition: opacity 200ms ease-out;
}
.fade-leave-active {
transition: opacity 300ms ease-out;
}
</style>
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
<!--
- @copyright 2021, Christopher Ng <chrng8@gmail.com>
-
- @author Christopher Ng <chrng8@gmail.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/>.
-->

<template>
<section>
<HeaderBar
:account-property="accountProperty"
label-for="company"
:is-editable="companyChangeSupported"
:is-valid-section="isValidSection"
:handle-scope-change="savePrimaryCompanyScope"
:scope.sync="primaryCompany.scope" />

<Company
:company.sync="primaryCompany.value"
:scope.sync="primaryCompany.scope" />
</section>
</template>

<script>
import { loadState } from '@nextcloud/initial-state'
import Company from './Company'
import HeaderBar from '../shared/HeaderBar'
import { ACCOUNT_PROPERTY_READABLE_ENUM } from '../../../constants/AccountPropertyConstants'
// import { savePrimaryCompanyScope } from '../../../service/PersonalInfo/CompanyService'
// import { validateCompany } from '../../../utils/validate'
console.log(loadState('settings', 'personalInfoParameters', {}))
const { companies: { primaryCompany } } = loadState('settings', 'personalInfoParameters', {})
export default {
name: 'CompanySection',
components: {
Company,
HeaderBar,
},
data() {
return {
accountProperty: ACCOUNT_PROPERTY_READABLE_ENUM.COMPANY,
primaryCompany,
// savePrimaryCompanyScope,
}
},
computed: {
isValidSection() {
// return validateCompany(this.primaryCompany.value)
},
},
}
</script>

<style lang="scss" scoped>
section {
padding: 10px 10px;
&::v-deep button:disabled {
cursor: default;
}
}
</style>
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ export default {
if (status === 'ok') {
// Ensure that local state reflects server state
this.initialDisplayName = displayName
emit('settings:displayName:updated', displayName)
emit('settings:display-name:updated', displayName)
this.showCheckmarkIcon = true
setTimeout(() => { this.showCheckmarkIcon = false }, 2000)
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ export default {
if (status === 'ok') {
// Ensure that local state reflects server state
this.initialProfileEnabled = isEnabled
emit('settings:profileEnabled:updated', isEnabled)
emit('settings:profile-enabled:updated', isEnabled)
this.showCheckmarkIcon = true
setTimeout(() => { this.showCheckmarkIcon = false }, 2000)
} else {
Expand Down
11 changes: 7 additions & 4 deletions apps/settings/src/main-personal-info.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import DisplayNameSection from './components/PersonalInfo/DisplayNameSection/Dis
import EmailSection from './components/PersonalInfo/EmailSection/EmailSection'
import LanguageSection from './components/PersonalInfo/LanguageSection/LanguageSection'
import ProfileSection from './components/PersonalInfo/ProfileSection/ProfileSection'
import CompanySection from './components/PersonalInfo/CompanySection/CompanySection'

__webpack_nonce__ = btoa(getRequestToken())

Expand All @@ -47,8 +48,10 @@ const DisplayNameView = Vue.extend(DisplayNameSection)
const EmailView = Vue.extend(EmailSection)
const LanguageView = Vue.extend(LanguageSection)
const ProfileView = Vue.extend(ProfileSection)
const CompanyView = Vue.extend(CompanySection)

new DisplayNameView().$mount('#vue-displaynamesection')
new EmailView().$mount('#vue-emailsection')
new LanguageView().$mount('#vue-languagesection')
new ProfileView().$mount('#vue-profilesection')
new DisplayNameView().$mount('#vue-displayname-section')
new EmailView().$mount('#vue-email-section')
new LanguageView().$mount('#vue-language-section')
new ProfileView().$mount('#vue-profile-section')
new CompanyView().$mount('#vue-company-section')
Loading

0 comments on commit a7799d5

Please sign in to comment.