Merge pull request #2487 from dpalou/MOBILE-3509

Mobile 3509
main
Juan Leyva 2020-08-25 21:33:08 +02:00 committed by GitHub
commit d041cfcf52
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 125 additions and 34 deletions

View File

@ -85,6 +85,7 @@ export class AddonModForumDiscussionPage implements OnDestroy {
protected forumId: number; protected forumId: number;
protected postId: number; protected postId: number;
protected parent: number;
protected onlineObserver: any; protected onlineObserver: any;
protected syncObserver: any; protected syncObserver: any;
protected syncManualObserver: any; protected syncManualObserver: any;
@ -120,6 +121,7 @@ export class AddonModForumDiscussionPage implements OnDestroy {
this.discussionId = this.discussion ? this.discussion.discussion : navParams.get('discussionId'); this.discussionId = this.discussion ? this.discussion.discussion : navParams.get('discussionId');
this.trackPosts = navParams.get('trackPosts'); this.trackPosts = navParams.get('trackPosts');
this.postId = navParams.get('postId'); this.postId = navParams.get('postId');
this.parent = navParams.get('parent');
this.isOnline = this.appProvider.isOnline(); this.isOnline = this.appProvider.isOnline();
this.onlineObserver = network.onchange().subscribe(() => { this.onlineObserver = network.onchange().subscribe(() => {
@ -136,41 +138,56 @@ export class AddonModForumDiscussionPage implements OnDestroy {
/** /**
* View loaded. * View loaded.
*/ */
ionViewDidLoad(): void { async ionViewDidLoad(): Promise<void> {
this.sitesProvider.getCurrentSite().getLocalSiteConfig('AddonModForumDiscussionSort').catch(() => { if (this.parent) {
this.userProvider.getUserPreference('forum_displaymode').catch(() => { this.sort = 'nested'; // Force nested order.
// Ignore errors. } else {
}).then((value) => { this.sort = await this.getUserSort();
const sortValue = value && parseInt(value, 10); }
switch (sortValue) { await this.fetchPosts(true, false, true);
const scrollTo = this.postId || this.parent;
if (scrollTo) {
// Scroll to the post.
setTimeout(() => {
this.domUtils.scrollToElementBySelector(this.content, '#addon-mod_forum-post-' + scrollTo);
});
}
}
/**
* Get sort type configured by the current user.
*
* @return Promise resolved with the sort type.
*/
protected async getUserSort(): Promise<SortType> {
try {
const value = await this.sitesProvider.getCurrentSite().getLocalSiteConfig('AddonModForumDiscussionSort');
return value;
} catch (error) {
try {
const value = await this.userProvider.getUserPreference('forum_displaymode');
switch (Number(value)) {
case 1: case 1:
this.sort = 'flat-oldest'; return 'flat-oldest';
break;
case -1: case -1:
this.sort = 'flat-newest'; return 'flat-newest';
break;
case 3: case 3:
this.sort = 'nested'; return 'nested';
break;
case 2: // Threaded not implemented. case 2: // Threaded not implemented.
default: default:
// Not set, use default sort. // Not set, use default sort.
// @TODO add fallback to $CFG->forum_displaymode. // @TODO add fallback to $CFG->forum_displaymode.
} }
}); } catch (error) {
}).then((value) => { // Ignore errors.
this.sort = value; }
}).finally(() => { }
this.fetchPosts(true, false, true).then(() => {
if (this.postId) { return 'flat-oldest';
// Scroll to the post.
setTimeout(() => {
this.domUtils.scrollToElementBySelector(this.content, '#addon-mod_forum-post-' + this.postId);
});
}
});
});
} }
/** /**

View File

@ -60,6 +60,9 @@ export class AddonModForumDiscussionLinkHandler extends CoreContentLinksHandlerB
if (data.postid || params.urlHash) { if (data.postid || params.urlHash) {
pageParams.postId = parseInt(data.postid || params.urlHash.replace('p', '')); pageParams.postId = parseInt(data.postid || params.urlHash.replace('p', ''));
} }
if (params.parent) {
pageParams.parent = parseInt(params.parent);
}
this.linkHelper.goInSite(navCtrl, 'AddonModForumDiscussionPage', pageParams, siteId); this.linkHelper.goInSite(navCtrl, 'AddonModForumDiscussionPage', pageParams, siteId);
} }

View File

@ -30,7 +30,7 @@
<p *ngIf="notification.userfromfullname">{{ notification.userfromfullname }}</p> <p *ngIf="notification.userfromfullname">{{ notification.userfromfullname }}</p>
</ion-item> </ion-item>
<ion-item text-wrap> <ion-item text-wrap>
<p><core-format-text [text]="notification.mobiletext | coreCreateLinks" contextLevel="system" [contextInstanceId]="0"></core-format-text></p> <p><core-format-text [text]="notification.mobiletext | coreCreateLinks" contextLevel="system" [contextInstanceId]="0" [maxHeight]="notification.displayfullhtml ? 120 : null"></core-format-text></p>
</ion-item> </ion-item>
<addon-notifications-actions [contextUrl]="notification.contexturl" [courseId]="notification.courseid" [data]="notification.customdata"></addon-notifications-actions> <addon-notifications-actions [contextUrl]="notification.contexturl" [courseId]="notification.courseid" [data]="notification.customdata"></addon-notifications-actions>
</ion-card> </ion-card>

View File

@ -1,5 +1,62 @@
page-addon-notifications-list .core-notification-icon { page-addon-notifications-list {
width: 34px; .core-notification-icon {
height: 34px; width: 34px;
margin: 10px !important; height: 34px;
} margin: 10px !important;
}
.item core-format-text {
.forumpost {
border: 1px solid $gray-light;
width: 100%;
margin: 0 0 1em 0;
td {
padding: $content-padding;
}
.header {
background-color: $gray-lighter;
}
.picture {
width: auto;
text-align: center;
}
.subject {
font-weight: 700;
margin-bottom: 1rem;
}
}
a {
text-decoration: none;
}
.userpicture {
border-radius: 50%;
}
.mdl-right {
@include text-align('end');
a {
display: none;
}
font {
font-size: 0.9em;
}
}
.commands {
display: none;
}
hr {
margin-top: 1.5rem;
margin-bottom: 1.5rem;
background-color: $gray-light;
}
}
}

View File

@ -204,8 +204,21 @@ export class AddonNotificationsListPage {
* @param notification The notification object. * @param notification The notification object.
*/ */
protected formatText(notification: AddonNotificationsAnyNotification): void { protected formatText(notification: AddonNotificationsAnyNotification): void {
const text = notification.mobiletext.replace(/-{4,}/ig, ''); notification.displayfullhtml = this.shouldDisplayFullHtml(notification);
notification.mobiletext = this.textUtils.replaceNewLines(text, '<br>');
notification.mobiletext = notification.displayfullhtml ?
notification.fullmessagehtml :
this.textUtils.replaceNewLines(notification.mobiletext.replace(/-{4,}/ig, ''), '<br>');
}
/**
* Check whether we should display full HTML of the notification.
*
* @param notification Notification.
* @return Whether to display full HTML.
*/
protected shouldDisplayFullHtml(notification: AddonNotificationsAnyNotification): boolean {
return notification.component == 'mod_forum' && notification.eventtype == 'digests';
} }
/** /**

View File

@ -616,4 +616,5 @@ export type AddonNotificationsNotificationCalculatedData = {
courseid?: number; // Calculated in the app. Course the notification belongs to. courseid?: number; // Calculated in the app. Course the notification belongs to.
profileimageurlfrom?: string; // Calculated in the app. Avatar of user that sent the notification. profileimageurlfrom?: string; // Calculated in the app. Avatar of user that sent the notification.
userfromfullname?: string; // Calculated in the app in some cases. User from full name. userfromfullname?: string; // Calculated in the app in some cases. User from full name.
displayfullhtml?: boolean; // Whether to display the full HTML of the notification.
}; };