MOBILE-3833 forum: Display post menu only if can edit or delete
parent
5445d24a57
commit
679f2e592f
|
@ -1,11 +1,11 @@
|
||||||
<core-loading [hideUntil]="loaded" [fullscreen]="false">
|
<core-loading [hideUntil]="loaded" [fullscreen]="false">
|
||||||
<ion-item button class="ion-text-wrap" (click)="editPost()" *ngIf="offlinePost || (canEdit && isOnline)" detail="false">
|
<ion-item button class="ion-text-wrap" (click)="editPost()" *ngIf="offlinePost || canEdit" detail="false">
|
||||||
<ion-icon name="fas-pen" slot="start" aria-hidden="true"></ion-icon>
|
<ion-icon name="fas-pen" slot="start" aria-hidden="true"></ion-icon>
|
||||||
<ion-label>
|
<ion-label>
|
||||||
<p class="item-heading">{{ 'addon.mod_forum.edit' | translate }}</p>
|
<p class="item-heading">{{ 'addon.mod_forum.edit' | translate }}</p>
|
||||||
</ion-label>
|
</ion-label>
|
||||||
</ion-item>
|
</ion-item>
|
||||||
<ion-item button class="ion-text-wrap" (click)="deletePost()" *ngIf="offlinePost || (canDelete && isOnline)" detail="false">
|
<ion-item button class="ion-text-wrap" (click)="deletePost()" *ngIf="offlinePost || canDelete" detail="false">
|
||||||
<ion-icon name="fas-trash" slot="start" aria-hidden="true"></ion-icon>
|
<ion-icon name="fas-trash" slot="start" aria-hidden="true"></ion-icon>
|
||||||
<ion-label>
|
<ion-label>
|
||||||
<p class="item-heading" *ngIf="!offlinePost">{{ 'addon.mod_forum.delete' | translate }}</p>
|
<p class="item-heading" *ngIf="!offlinePost">{{ 'addon.mod_forum.delete' | translate }}</p>
|
||||||
|
|
|
@ -12,13 +12,13 @@
|
||||||
// See the License for the specific language governing permissions and
|
// See the License for the specific language governing permissions and
|
||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
|
|
||||||
import { Component, Input, OnDestroy, OnInit } from '@angular/core';
|
import { Component, Input, OnInit } from '@angular/core';
|
||||||
import { CoreSites, CoreSitesReadingStrategy } from '@services/sites';
|
import { CoreSites, CoreSitesReadingStrategy } from '@services/sites';
|
||||||
import { CoreApp } from '@services/app';
|
import { CoreApp } from '@services/app';
|
||||||
import { AddonModForum, AddonModForumPost } from '@addons/mod/forum/services/forum';
|
import { AddonModForum, AddonModForumPost } from '@addons/mod/forum/services/forum';
|
||||||
import { Network, NgZone, PopoverController } from '@singletons';
|
import { PopoverController } from '@singletons';
|
||||||
import { Subscription } from 'rxjs';
|
|
||||||
import { CoreDomUtils } from '@services/utils/dom';
|
import { CoreDomUtils } from '@services/utils/dom';
|
||||||
|
import { CoreNetworkError } from '@classes/errors/network-error';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This component is meant to display a popover with the post options.
|
* This component is meant to display a popover with the post options.
|
||||||
|
@ -28,7 +28,7 @@ import { CoreDomUtils } from '@services/utils/dom';
|
||||||
templateUrl: 'post-options-menu.html',
|
templateUrl: 'post-options-menu.html',
|
||||||
styleUrls: ['./post-options-menu.scss'],
|
styleUrls: ['./post-options-menu.scss'],
|
||||||
})
|
})
|
||||||
export class AddonModForumPostOptionsMenuComponent implements OnInit, OnDestroy {
|
export class AddonModForumPostOptionsMenuComponent implements OnInit {
|
||||||
|
|
||||||
@Input() post!: AddonModForumPost; // The post.
|
@Input() post!: AddonModForumPost; // The post.
|
||||||
@Input() cmId!: number;
|
@Input() cmId!: number;
|
||||||
|
@ -38,32 +38,15 @@ export class AddonModForumPostOptionsMenuComponent implements OnInit, OnDestroy
|
||||||
canDelete = false;
|
canDelete = false;
|
||||||
loaded = false;
|
loaded = false;
|
||||||
url?: string;
|
url?: string;
|
||||||
isOnline!: boolean;
|
offlinePost = false;
|
||||||
offlinePost!: boolean;
|
|
||||||
|
|
||||||
protected onlineObserver?: Subscription;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Component being initialized.
|
* @inheritdoc
|
||||||
*/
|
*/
|
||||||
async ngOnInit(): Promise<void> {
|
async ngOnInit(): Promise<void> {
|
||||||
this.isOnline = CoreApp.isOnline();
|
this.offlinePost = this.post.id < 0;
|
||||||
|
if (this.offlinePost) {
|
||||||
this.onlineObserver = Network.onChange().subscribe(() => {
|
|
||||||
// Execute the callback in the Angular zone, so change detection doesn't stop working.
|
|
||||||
NgZone.run(() => {
|
|
||||||
this.isOnline = CoreApp.isOnline();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
if (this.post.id > 0) {
|
|
||||||
const site = CoreSites.getRequiredCurrentSite();
|
|
||||||
this.url = site.createSiteUrl('/mod/forum/discuss.php', { d: this.post.discussionid.toString() }, 'p' + this.post.id);
|
|
||||||
this.offlinePost = false;
|
|
||||||
} else {
|
|
||||||
// Offline post, you can edit or discard the post.
|
|
||||||
this.loaded = true;
|
this.loaded = true;
|
||||||
this.offlinePost = true;
|
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -81,6 +64,8 @@ export class AddonModForumPostOptionsMenuComponent implements OnInit, OnDestroy
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
this.loaded = true;
|
this.loaded = true;
|
||||||
|
// Display the open in browser button to prevent having an empty menu.
|
||||||
|
this.setOpenInBrowserUrl();
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -88,14 +73,20 @@ export class AddonModForumPostOptionsMenuComponent implements OnInit, OnDestroy
|
||||||
|
|
||||||
this.canDelete = !!this.post.capabilities.delete && AddonModForum.isDeletePostAvailable();
|
this.canDelete = !!this.post.capabilities.delete && AddonModForum.isDeletePostAvailable();
|
||||||
this.canEdit = !!this.post.capabilities.edit && AddonModForum.isUpdatePostAvailable();
|
this.canEdit = !!this.post.capabilities.edit && AddonModForum.isUpdatePostAvailable();
|
||||||
|
if (!this.canDelete && !this.canEdit) {
|
||||||
|
// Display the open in browser button to prevent having an empty menu.
|
||||||
|
this.setOpenInBrowserUrl();
|
||||||
|
}
|
||||||
|
|
||||||
this.loaded = true;
|
this.loaded = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Component destroyed.
|
* Set the URL to open in browser.
|
||||||
*/
|
*/
|
||||||
ngOnDestroy(): void {
|
protected setOpenInBrowserUrl(): void {
|
||||||
this.onlineObserver?.unsubscribe();
|
const site = CoreSites.getRequiredCurrentSite();
|
||||||
|
this.url = site.createSiteUrl('/mod/forum/discuss.php', { d: this.post.discussionid.toString() }, 'p' + this.post.id);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -110,6 +101,12 @@ export class AddonModForumPostOptionsMenuComponent implements OnInit, OnDestroy
|
||||||
*/
|
*/
|
||||||
deletePost(): void {
|
deletePost(): void {
|
||||||
if (!this.offlinePost) {
|
if (!this.offlinePost) {
|
||||||
|
if (!CoreApp.isOnline()) {
|
||||||
|
CoreDomUtils.showErrorModal(new CoreNetworkError());
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
PopoverController.dismiss({ action: 'delete' });
|
PopoverController.dismiss({ action: 'delete' });
|
||||||
} else {
|
} else {
|
||||||
PopoverController.dismiss({ action: 'deleteoffline' });
|
PopoverController.dismiss({ action: 'deleteoffline' });
|
||||||
|
@ -120,6 +117,12 @@ export class AddonModForumPostOptionsMenuComponent implements OnInit, OnDestroy
|
||||||
* Edit a post.
|
* Edit a post.
|
||||||
*/
|
*/
|
||||||
editPost(): void {
|
editPost(): void {
|
||||||
|
if (!this.offlinePost && !CoreApp.isOnline()) {
|
||||||
|
CoreDomUtils.showErrorModal(new CoreNetworkError());
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
PopoverController.dismiss({ action: 'edit' });
|
PopoverController.dismiss({ action: 'edit' });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -116,9 +116,16 @@ export class AddonModForumPostComponent implements OnInit, OnDestroy, OnChanges
|
||||||
this.defaultReplySubject = this.post.replysubject || ((this.post.subject.startsWith('Re: ') ||
|
this.defaultReplySubject = this.post.replysubject || ((this.post.subject.startsWith('Re: ') ||
|
||||||
this.post.subject.startsWith(reTranslated)) ? this.post.subject : `${reTranslated} ${this.post.subject}`);
|
this.post.subject.startsWith(reTranslated)) ? this.post.subject : `${reTranslated} ${this.post.subject}`);
|
||||||
|
|
||||||
|
if (this.post.id < 0) {
|
||||||
|
this.optionsMenuEnabled = true;
|
||||||
|
} else if (this.post.capabilities.delete !== undefined) {
|
||||||
|
this.optionsMenuEnabled = this.post.capabilities.delete === true || this.post.capabilities.edit === true;
|
||||||
|
} else {
|
||||||
|
// Cannot know if the user can edit/delete or not, display the menu if the WebServices are available.
|
||||||
this.optionsMenuEnabled = this.post.id < 0 || (AddonModForum.isGetDiscussionPostAvailable() &&
|
this.optionsMenuEnabled = this.post.id < 0 || (AddonModForum.isGetDiscussionPostAvailable() &&
|
||||||
(AddonModForum.isDeletePostAvailable() || AddonModForum.isUpdatePostAvailable()));
|
(AddonModForum.isDeletePostAvailable() || AddonModForum.isUpdatePostAvailable()));
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Detect changes on input properties.
|
* Detect changes on input properties.
|
||||||
|
|
|
@ -53,6 +53,8 @@
|
||||||
[content]="'addon.mod_forum.removefromfavourites' | translate" iconAction="fas-star" [iconSlash]="true"
|
[content]="'addon.mod_forum.removefromfavourites' | translate" iconAction="fas-star" [iconSlash]="true"
|
||||||
(action)="toggleFavouriteState(false)">
|
(action)="toggleFavouriteState(false)">
|
||||||
</core-context-menu-item>
|
</core-context-menu-item>
|
||||||
|
<core-context-menu-item [hidden]="!externalUrl" [priority]="100" [content]="'core.openinbrowser' | translate" [href]="externalUrl"
|
||||||
|
iconAction="fas-external-link-alt" [showBrowserWarning]="false"></core-context-menu-item>
|
||||||
</core-context-menu>
|
</core-context-menu>
|
||||||
</core-navbar-buttons>
|
</core-navbar-buttons>
|
||||||
<ion-content [core-swipe-navigation]="discussions" class="limited-width">
|
<ion-content [core-swipe-navigation]="discussions" class="limited-width">
|
||||||
|
|
|
@ -107,6 +107,7 @@ export class AddonModForumDiscussionPage implements OnInit, AfterViewInit, OnDes
|
||||||
availabilityMessage: string | null = null;
|
availabilityMessage: string | null = null;
|
||||||
showQAMessage = false;
|
showQAMessage = false;
|
||||||
leavingPage = false;
|
leavingPage = false;
|
||||||
|
externalUrl?: string;
|
||||||
|
|
||||||
protected forumId?: number;
|
protected forumId?: number;
|
||||||
protected postId?: number;
|
protected postId?: number;
|
||||||
|
@ -164,6 +165,7 @@ export class AddonModForumDiscussionPage implements OnInit, AfterViewInit, OnDes
|
||||||
}
|
}
|
||||||
|
|
||||||
this.isOnline = CoreApp.isOnline();
|
this.isOnline = CoreApp.isOnline();
|
||||||
|
this.externalUrl = CoreSites.getCurrentSite()?.createSiteUrl('/mod/forum/discuss.php', { d: this.discussionId.toString() });
|
||||||
this.onlineObserver = Network.onChange().subscribe(() => {
|
this.onlineObserver = Network.onChange().subscribe(() => {
|
||||||
// Execute the callback in the Angular zone, so change detection doesn't stop working.
|
// Execute the callback in the Angular zone, so change detection doesn't stop working.
|
||||||
NgZone.run(() => {
|
NgZone.run(() => {
|
||||||
|
|
Loading…
Reference in New Issue