Commit 40a5b066 by Diana Huang Committed by GitHub

Merge pull request #15843 from edx/robrap/LEARNER-1858-show-join-date-2

Support for joined date to profile.
parents 04da157e 7cc9400b
...@@ -2928,6 +2928,7 @@ ACCOUNT_VISIBILITY_CONFIGURATION = { ...@@ -2928,6 +2928,7 @@ ACCOUNT_VISIBILITY_CONFIGURATION = {
'profile_image', 'profile_image',
'country', 'country',
'time_zone', 'time_zone',
'date_joined',
'language_proficiencies', 'language_proficiencies',
'bio', 'bio',
'account_privacy', 'account_privacy',
...@@ -2946,10 +2947,10 @@ ACCOUNT_VISIBILITY_CONFIGURATION = { ...@@ -2946,10 +2947,10 @@ ACCOUNT_VISIBILITY_CONFIGURATION = {
"admin_fields": [ "admin_fields": [
"username", "username",
"email", "email",
"date_joined",
"is_active", "is_active",
"bio", "bio",
"country", "country",
"date_joined",
"profile_image", "profile_image",
"language_proficiencies", "language_proficiencies",
"name", "name",
......
...@@ -74,7 +74,8 @@ define(['underscore'], function(_) { ...@@ -74,7 +74,8 @@ define(['underscore'], function(_) {
year_of_birth: '3', // Note: test birth year range is a string from 0-3 year_of_birth: '3', // Note: test birth year range is a string from 0-3
requires_parental_consent: false, requires_parental_consent: false,
country: '1', country: '1',
language: null, language: 'en-US',
date_joined: 'December 17, 1995 03:24:00',
bio: 'About the student', bio: 'About the student',
language_proficiencies: [{code: '1'}], language_proficiencies: [{code: '1'}],
profile_image: PROFILE_IMAGE, profile_image: PROFILE_IMAGE,
...@@ -82,7 +83,7 @@ define(['underscore'], function(_) { ...@@ -82,7 +83,7 @@ define(['underscore'], function(_) {
}; };
var DEFAULT_USER_PREFERENCES_DATA = { var DEFAULT_USER_PREFERENCES_DATA = {
'pref-lang': '2', 'pref-lang': '2',
'time_zone': null time_zone: 'America/New_York'
}; };
var createAccountSettingsData = function(options) { var createAccountSettingsData = function(options) {
......
...@@ -326,19 +326,6 @@ define(['backbone', 'jquery', 'underscore', 'edx-ui-toolkit/js/utils/spec-helper ...@@ -326,19 +326,6 @@ define(['backbone', 'jquery', 'underscore', 'edx-ui-toolkit/js/utils/spec-helper
expect(view.$('.u-field-value > a .u-field-link-title-' + view.options.valueAttribute).text().trim()).toBe(fieldData.linkTitle); expect(view.$('.u-field-value > a .u-field-link-title-' + view.options.valueAttribute).text().trim()).toBe(fieldData.linkTitle);
}); });
it('correctly renders LinkFieldView', function() {
var fieldData = FieldViewsSpecHelpers.createFieldData(FieldViews.LinkFieldView, {
title: 'Title',
linkTitle: 'Link title',
helpMessage: 'Click the link.',
valueAttribute: 'password-reset'
});
var view = new FieldViews.LinkFieldView(fieldData).render();
FieldViewsSpecHelpers.expectTitleAndMessageToContain(view, fieldData.title, fieldData.helpMessage);
expect(view.$('.u-field-value > a .u-field-link-title-' + view.options.valueAttribute).text().trim()).toBe(fieldData.linkTitle);
});
it("can't persist changes if persistChanges is off", function() { it("can't persist changes if persistChanges is off", function() {
requests = AjaxHelpers.requests(this); requests = AjaxHelpers.requests(this);
var fieldClasses = [ var fieldClasses = [
...@@ -350,5 +337,21 @@ define(['backbone', 'jquery', 'underscore', 'edx-ui-toolkit/js/utils/spec-helper ...@@ -350,5 +337,21 @@ define(['backbone', 'jquery', 'underscore', 'edx-ui-toolkit/js/utils/spec-helper
FieldViewsSpecHelpers.verifyPersistence(fieldClasses[i], requests); FieldViewsSpecHelpers.verifyPersistence(fieldClasses[i], requests);
} }
}); });
it('correctly renders DateFieldView', function() {
var fieldData = FieldViewsSpecHelpers.createFieldData(FieldViews.DateFieldView, {
title: 'Title',
helpMessage: '',
dateFormat: 'MMM YYYY',
valueAttribute: 'date_joined',
userLanguage: 'en-US',
userTimezone: 'America/New_York'
}),
joinDate = new Date(1990, 0, 15),
view;
fieldData.model.set({date_joined: joinDate.toDateString()});
view = new FieldViews.DateFieldView(fieldData).render();
expect(view.$('.u-field-value').text().trim()).toBe('Jan 1990');
});
}); });
}); });
...@@ -3,13 +3,14 @@ ...@@ -3,13 +3,14 @@
define([ define([
'gettext', 'jquery', 'underscore', 'backbone', 'gettext', 'jquery', 'underscore', 'backbone',
'edx-ui-toolkit/js/utils/html-utils', 'edx-ui-toolkit/js/utils/html-utils',
'edx-ui-toolkit/js/utils/date-utils',
'text!templates/fields/field_readonly.underscore', 'text!templates/fields/field_readonly.underscore',
'text!templates/fields/field_dropdown.underscore', 'text!templates/fields/field_dropdown.underscore',
'text!templates/fields/field_link.underscore', 'text!templates/fields/field_link.underscore',
'text!templates/fields/field_text.underscore', 'text!templates/fields/field_text.underscore',
'text!templates/fields/field_textarea.underscore', 'text!templates/fields/field_textarea.underscore',
'backbone-super' 'backbone-super'
], function(gettext, $, _, Backbone, HtmlUtils, ], function(gettext, $, _, Backbone, HtmlUtils, DateUtils,
field_readonly_template, field_readonly_template,
field_dropdown_template, field_dropdown_template,
field_link_template, field_link_template,
...@@ -313,6 +314,38 @@ ...@@ -313,6 +314,38 @@
} }
}); });
FieldViews.DateFieldView = FieldViews.ReadonlyFieldView.extend({
fieldType: 'date',
timezoneFormattedDate: function() {
var context;
context = {
datetime: new Date(this.modelValue()),
language: this.options.userLanguage,
timezone: this.options.userTimezone,
format: this.options.dateFormat
};
return DateUtils.localize(context);
},
render: function() {
HtmlUtils.setHtml(this.$el, HtmlUtils.template(this.fieldTemplate)({
id: this.options.valueAttribute,
title: this.options.title,
screenReaderTitle: this.options.screenReaderTitle || this.options.title,
value: this.timezoneFormattedDate(),
message: this.helpMessage
}));
this.delegateEvents();
return this;
},
updateValueInField: function() {
this.$('.u-field-value ').text(this.timezoneFormattedDate());
}
});
FieldViews.TextFieldView = FieldViews.EditableFieldView.extend({ FieldViews.TextFieldView = FieldViews.EditableFieldView.extend({
fieldType: 'text', fieldType: 'text',
......
...@@ -235,7 +235,7 @@ ...@@ -235,7 +235,7 @@
} }
.u-field-value-readonly { .u-field-value-readonly {
@extend %t-weight3; font-weight: 500;
font-family: $sans-serif; font-family: $sans-serif;
color: $darkest-base-font-color; color: $darkest-base-font-color;
} }
...@@ -245,14 +245,7 @@ ...@@ -245,14 +245,7 @@
display: block; display: block;
} }
&.u-field-dropdown { &:not(.u-field-readonly):not(:last-child) {
position: relative;
&:not(.editable-never) {
cursor: pointer;
}
&:not(:last-child) {
padding-bottom: $baseline/4; padding-bottom: $baseline/4;
border-bottom: 1px solid $gray-lighter; border-bottom: 1px solid $gray-lighter;
...@@ -261,6 +254,13 @@ ...@@ -261,6 +254,13 @@
border-bottom: 2px dashed $link-color; border-bottom: 2px dashed $link-color;
} }
} }
&.u-field-dropdown {
position: relative;
&:not(.editable-never) {
cursor: pointer;
}
} }
} }
......
...@@ -222,7 +222,7 @@ class TestAccountsAPI(CacheIsolationTestCase, UserAPITestCase): ...@@ -222,7 +222,7 @@ class TestAccountsAPI(CacheIsolationTestCase, UserAPITestCase):
Verify that the shareable fields from the account are returned Verify that the shareable fields from the account are returned
""" """
data = response.data data = response.data
self.assertEqual(8, len(data)) self.assertEqual(9, len(data))
self.assertEqual(self.user.username, data["username"]) self.assertEqual(self.user.username, data["username"])
self.assertEqual("US", data["country"]) self.assertEqual("US", data["country"])
self._verify_profile_image_data(data, True) self._verify_profile_image_data(data, True)
......
...@@ -103,6 +103,18 @@ ...@@ -103,6 +103,18 @@
}); });
sectionOneFieldViews = [ sectionOneFieldViews = [
new FieldsView.DateFieldView({
title: gettext('Joined'),
titleVisible: true,
model: accountSettingsModel,
screenReaderTitle: gettext('Joined Date'),
valueAttribute: 'date_joined',
helpMessage: '',
userLanguage: accountSettingsModel.get('language'),
userTimezone: accountPreferencesModel.get('time_zone'),
dateFormat: 'MMMM YYYY' // not localized, but hopefully ok.
}),
new FieldsView.DropdownFieldView({ new FieldsView.DropdownFieldView({
title: gettext('Location'), title: gettext('Location'),
titleVisible: true, titleVisible: true,
......
...@@ -103,6 +103,12 @@ define( ...@@ -103,6 +103,12 @@ define(
valueAttribute: 'language_proficiencies', valueAttribute: 'language_proficiencies',
options: Helpers.FIELD_OPTIONS, options: Helpers.FIELD_OPTIONS,
helpMessage: '' helpMessage: ''
}),
new FieldViews.DateFieldView({
model: accountSettingsModel,
valueAttribute: 'date_joined',
helpMessage: ''
}) })
]; ];
......
...@@ -12,6 +12,8 @@ define(['underscore', 'URI', 'edx-ui-toolkit/js/utils/spec-helpers/ajax-helpers' ...@@ -12,6 +12,8 @@ define(['underscore', 'URI', 'edx-ui-toolkit/js/utils/spec-helpers/ajax-helpers'
if ('fieldValue' in view || 'imageUrl' in view) { if ('fieldValue' in view || 'imageUrl' in view) {
if ('imageUrl' in view) { if ('imageUrl' in view) {
expect($($element.find('.image-frame')[0]).attr('src')).toBe(view.imageUrl()); expect($($element.find('.image-frame')[0]).attr('src')).toBe(view.imageUrl());
} else if (view.fieldType === 'date') {
expect(view.fieldValue()).toBe(view.timezoneFormattedDate());
} else if (view.fieldValue()) { } else if (view.fieldValue()) {
expect(view.fieldValue()).toBe(view.modelValue()); expect(view.fieldValue()).toBe(view.modelValue());
} else if ('optionForValue' in view) { } else if ('optionForValue' in view) {
...@@ -41,7 +43,7 @@ define(['underscore', 'URI', 'edx-ui-toolkit/js/utils/spec-helpers/ajax-helpers' ...@@ -41,7 +43,7 @@ define(['underscore', 'URI', 'edx-ui-toolkit/js/utils/spec-helpers/ajax-helpers'
var expectSectionOneTobeRendered = function(learnerProfileView) { var expectSectionOneTobeRendered = function(learnerProfileView) {
var sectionOneFieldElements = $(learnerProfileView.$('.wrapper-profile-section-one')).find('.u-field'); var sectionOneFieldElements = $(learnerProfileView.$('.wrapper-profile-section-one')).find('.u-field');
expect(sectionOneFieldElements.length).toBe(5); expect(sectionOneFieldElements.length).toBe(6);
expectProfileElementContainsField(sectionOneFieldElements[0], learnerProfileView.options.profileImageFieldView); expectProfileElementContainsField(sectionOneFieldElements[0], learnerProfileView.options.profileImageFieldView);
expectProfileElementContainsField(sectionOneFieldElements[1], learnerProfileView.options.usernameFieldView); expectProfileElementContainsField(sectionOneFieldElements[1], learnerProfileView.options.usernameFieldView);
expectProfileElementContainsField(sectionOneFieldElements[2], learnerProfileView.options.nameFieldView); expectProfileElementContainsField(sectionOneFieldElements[2], learnerProfileView.options.nameFieldView);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment