-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
MOBILE-4374 user: Implement social profile fields
- Loading branch information
1 parent
8c97b6f
commit c0043fc
Showing
7 changed files
with
203 additions
and
4 deletions.
There are no files selected for viewing
28 changes: 28 additions & 0 deletions
28
src/addons/userprofilefield/social/component/addon-user-profile-field-social.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<!-- Render (no edit). --> | ||
<ion-item *ngIf="!edit && field && field.name"> | ||
<ion-label> | ||
<p class="item-heading"> | ||
<core-format-text [text]="field.name" [contextLevel]="contextLevel" [contextInstanceId]="contextInstanceId" | ||
[courseId]="courseId" [wsNotFiltered]="true"> | ||
</core-format-text> | ||
</p> | ||
<p> | ||
<core-format-text [text]="value" [contextLevel]="contextLevel" [contextInstanceId]="contextInstanceId" [courseId]="courseId" | ||
[wsNotFiltered]="valueNotFiltered"> | ||
</core-format-text> | ||
</p> | ||
</ion-label> | ||
</ion-item> | ||
|
||
<!-- Edit. --> | ||
<ion-item *ngIf="edit && field && field.shortname && form" class="ion-text-wrap" [formGroup]="form"> | ||
<ion-label position="stacked"> | ||
<span [core-mark-required]="required"> | ||
<core-format-text [text]="field.name" [contextLevel]="contextLevel" [contextInstanceId]="contextInstanceId" | ||
[courseId]="courseId" [wsNotFiltered]="true"> | ||
</core-format-text> | ||
</span> | ||
</ion-label> | ||
<ion-input type="text" [formControlName]="modelName" [placeholder]="field.name"></ion-input> | ||
<core-input-errors [control]="form.controls[modelName]"></core-input-errors> | ||
</ion-item> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
// (C) Copyright 2015 Moodle Pty Ltd. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
import { Component } from '@angular/core'; | ||
|
||
import { CoreUserProfileFieldBaseComponent } from '@features/user/classes/base-profilefield-component'; | ||
|
||
/** | ||
* Directive to render a social user profile field. | ||
*/ | ||
@Component({ | ||
selector: 'addon-user-profile-field-social', | ||
templateUrl: 'addon-user-profile-field-social.html', | ||
}) | ||
export class AddonUserProfileFieldSocialComponent extends CoreUserProfileFieldBaseComponent { | ||
|
||
} |
79 changes: 79 additions & 0 deletions
79
src/addons/userprofilefield/social/services/handlers/social.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
// (C) Copyright 2015 Moodle Pty Ltd. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
import { Injectable, Type } from '@angular/core'; | ||
|
||
import { CoreUserProfileFieldHandler, CoreUserProfileFieldHandlerData } from '@features/user/services/user-profile-field-delegate'; | ||
import { AddonUserProfileFieldSocialComponent } from '../../component/social'; | ||
import { CoreTextUtils } from '@services/utils/text'; | ||
import { AuthEmailSignupProfileField } from '@features/login/services/login-helper'; | ||
import { CoreUserProfileField } from '@features/user/services/user'; | ||
import { makeSingleton } from '@singletons'; | ||
import { CoreFormFields } from '@singletons/form'; | ||
|
||
/** | ||
* Social user profile field handlers. | ||
*/ | ||
@Injectable({ providedIn: 'root' }) | ||
export class AddonUserProfileFieldSocialHandlerService implements CoreUserProfileFieldHandler { | ||
|
||
name = 'AddonUserProfileFieldSocial'; | ||
type = 'social'; | ||
|
||
/** | ||
* Whether or not the handler is enabled on a site level. | ||
* | ||
* @returns True or promise resolved with true if enabled. | ||
*/ | ||
async isEnabled(): Promise<boolean> { | ||
return true; | ||
} | ||
|
||
/** | ||
* Get the data to send for the field based on the input data. | ||
* | ||
* @param field User field to get the data for. | ||
* @param signup True if user is in signup page. | ||
* @param registerAuth Register auth method. E.g. 'email'. | ||
* @param formValues Form Values. | ||
* @returns Data to send for the field. | ||
*/ | ||
async getData( | ||
field: AuthEmailSignupProfileField | CoreUserProfileField, | ||
signup: boolean, | ||
registerAuth: string, | ||
formValues: CoreFormFields, | ||
): Promise<CoreUserProfileFieldHandlerData | undefined> { | ||
const name = 'profile_field_' + field.shortname; | ||
|
||
return { | ||
type: 'social', | ||
name: name, | ||
value: CoreTextUtils.cleanTags(<string> formValues[name]), | ||
}; | ||
} | ||
|
||
/** | ||
* Return the Component to use to display the user profile field. | ||
* It's recommended to return the class of the component, but you can also return an instance of the component. | ||
* | ||
* @returns The component (or promise resolved with component) to use, undefined if not found. | ||
*/ | ||
getComponent(): Type<unknown> | Promise<Type<unknown>> { | ||
return AddonUserProfileFieldSocialComponent; | ||
} | ||
|
||
} | ||
|
||
export const AddonUserProfileFieldSocialHandler = makeSingleton(AddonUserProfileFieldSocialHandlerService); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
// (C) Copyright 2015 Moodle Pty Ltd. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
import { APP_INITIALIZER, NgModule } from '@angular/core'; | ||
|
||
import { AddonUserProfileFieldSocialHandler } from './services/handlers/social'; | ||
import { CoreUserProfileFieldDelegate } from '@features/user/services/user-profile-field-delegate'; | ||
import { AddonUserProfileFieldSocialComponent } from './component/social'; | ||
import { CoreSharedModule } from '@/core/shared.module'; | ||
|
||
@NgModule({ | ||
declarations: [ | ||
AddonUserProfileFieldSocialComponent, | ||
], | ||
imports: [ | ||
CoreSharedModule, | ||
], | ||
providers: [ | ||
{ | ||
provide: APP_INITIALIZER, | ||
multi: true, | ||
useValue: () => { | ||
CoreUserProfileFieldDelegate.registerHandler(AddonUserProfileFieldSocialHandler.instance); | ||
}, | ||
}, | ||
], | ||
exports: [ | ||
AddonUserProfileFieldSocialComponent, | ||
], | ||
}) | ||
export class AddonUserProfileFieldSocialModule {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,8 +8,9 @@ Feature: Test basic usage of user features | |
|
||
Scenario: Complete missing fields | ||
Given the following "custom profile fields" exist: | ||
| datatype | shortname | name | required | | ||
| text | food | Favourite food | 1 | | ||
| datatype | shortname | name | required | param1 | | ||
| text | food | Favourite food | 1 | | | ||
| social | website | url | 1 | url | | ||
When I enter the app | ||
And I log in as "student1" | ||
Then I should find "Complete your profile" in the app | ||
|
@@ -42,6 +43,7 @@ Feature: Test basic usage of user features | |
And I set the field "password" to "student1" | ||
And I click on "Log in" "button" | ||
And I set the field "Favourite food" to "Pasta" | ||
And I set the field "Web page" to "https://moodle.com" | ||
And I click on "Update profile" "button" | ||
Then I should see "Changes saved" | ||
|
||
|
@@ -53,11 +55,29 @@ Feature: Test basic usage of user features | |
Then I should find "Acceptance test site" in the app | ||
|
||
Scenario: View profile | ||
Given I entered the app as "student1" | ||
When I press the user menu button in the app | ||
Given the following "custom profile fields" exist: | ||
| datatype | shortname | name | required | param1 | | ||
| text | food | Favourite food | 1 | | | ||
| social | website | url | 1 | url | | ||
And I entered the app as "student1" | ||
And I press "Complete profile" in the app | ||
And I switch to the browser tab opened by the app | ||
And I set the field "username" to "student1" | ||
And I set the field "password" to "student1" | ||
And I click on "Log in" "button" | ||
And I set the field "Favourite food" to "Pasta" | ||
And I set the field "Web page" to "https://moodle.com" | ||
When I click on "Update profile" "button" | ||
Then I should see "Changes saved" | ||
|
||
When I close the browser tab opened by the app | ||
And I press "Reconnect" in the app | ||
And I press the user menu button in the app | ||
And I press "Student" in the app | ||
Then I should find "[email protected]" in the app | ||
And I should find "Student Student" in the app | ||
And I should find "Pasta" in the app | ||
And I should find "https://moodle.com" in the app | ||
And the UI should match the snapshot | ||
|
||
@lms_from4.2 | ||
|
Binary file renamed
BIN
+19.4 KB
...usage-of-user-features-view-profile_7.png → ...sage-of-user-features-view-profile_21.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.