Skip to content

Commit

Permalink
Issue #SH-21 merge: Merge pull request #1014 from AmiableAnil/Release…
Browse files Browse the repository at this point in the history
…-3.1.0-router

Issue #SH-21 feat: Integrated APIs for groups.
  • Loading branch information
AmiableAnil authored Jul 2, 2020
2 parents 769831e + 155e6d3 commit 187c51c
Show file tree
Hide file tree
Showing 10 changed files with 247 additions and 198 deletions.
22 changes: 14 additions & 8 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,10 @@
"@ionic/angular": "^4.11.2",
"@ngx-translate/core": "^11.0.1",
"@ngx-translate/http-loader": "^4.0.0",
"@project-sunbird/client-services": "^3.1.7",
"@project-sunbird/client-services": "^3.1.8",
"@project-sunbird/common-consumption": "^3.1.2",
"@project-sunbird/content-player": "3.1.0",
"@project-sunbird/sunbird-sdk": "~3.1.7",
"@project-sunbird/sunbird-sdk": "~3.1.8",
"code-push": "^3.0.1",
"com.jjdltc.cordova.plugin.zip": "https://github.com/swayangjit/jjdltc-cordova-plugin-zip.git",
"com.telerik.plugins.nativepagetransitions": "^0.6.5",
Expand Down Expand Up @@ -249,4 +249,4 @@
},
"transformIgnorePatterns": []
}
}
}
49 changes: 25 additions & 24 deletions src/app/curriculum-courses/curriculum-courses.page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ import { Router } from '@angular/router';
import { RouterLinks, ProfileConstants } from '../app.constant';
import { TranslateService } from '@ngx-translate/core';
import { CourseService, Course, CorrelationData, TelemetryObject, GetUserEnrolledCoursesRequest } from '@project-sunbird/sunbird-sdk';
import {Subscription} from 'rxjs';
import {Location} from '@angular/common';
import {Platform} from '@ionic/angular';
import { Subscription } from 'rxjs';
import { Location } from '@angular/common';
import { Platform } from '@ionic/angular';
import { AppHeaderService } from '@app/services/app-header.service';
import {ContentUtil} from '@app/util/content-util';
import { ContentUtil } from '@app/util/content-util';

@Component({
selector: 'app-curriculum-courses',
Expand Down Expand Up @@ -67,10 +67,10 @@ export class CurriculumCoursesPage implements OnInit {
this.location.back();
});
this.telemetryGeneratorService.generateImpressionTelemetry(
ImpressionType.VIEW,
'',
PageId.COURSE_LIST,
Environment.HOME
ImpressionType.VIEW,
'',
PageId.COURSE_LIST,
Environment.HOME
);
}

Expand All @@ -83,16 +83,17 @@ export class CurriculumCoursesPage implements OnInit {
}
}

async ngOnInit() {
ngOnInit() {
if (this.appGlobalService.isUserLoggedIn()) {
// TODO: get the current userId
const sessionObj = this.appGlobalService.getSessionData();
const userId = sessionObj[ProfileConstants.USER_TOKEN];
try {
this.enrolledCourses = await this.getEnrolledCourses(userId);
} catch (error) {
console.error('CurriculumCoursesPage', error);
}
this.appGlobalService.getActiveProfileUid()
.then(async (uid) => {
try {
this.enrolledCourses = await this.getEnrolledCourses(uid);
} catch (error) {
console.error('CurriculumCoursesPage', error);
}
});
}

this.mergeCourseList(this.enrolledCourses, this.courseList);
Expand All @@ -103,14 +104,14 @@ export class CurriculumCoursesPage implements OnInit {
this.corRelationList = this.commonUtilService.deDupe(this.corRelationList, 'type');
const telemetryObject: TelemetryObject = ContentUtil.getTelemetryObject(course);
this.telemetryGeneratorService.generateInteractTelemetry(
InteractType.TOUCH,
InteractSubtype.CONTENT_CLICKED,
Environment.HOME,
PageId.COURSE_LIST,
telemetryObject,
undefined,
ContentUtil.generateRollUp(undefined, course.identifier),
this.corRelationList);
InteractType.TOUCH,
InteractSubtype.CONTENT_CLICKED,
Environment.HOME,
PageId.COURSE_LIST,
telemetryObject,
undefined,
ContentUtil.generateRollUp(undefined, course.identifier),
this.corRelationList);
this.router.navigate([RouterLinks.ENROLLED_COURSE_DETAILS], {
state: {
content: course,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,12 @@ <h3>{{userName}}</h3>
</ion-content>
<ion-footer>
<div class="au-btn" *ngIf="!isUserIdVerified">
<button class="sb-btn-large" [class.inactive]="!userId" (click)="onVerify()">
<button class="sb-btn-large" [class.inactive]="!userId" (click)="onVerifyClick()">
{{'VERIFY' | translate}}
</button>
</div>
<div class="au-btn" *ngIf="isUserIdVerified">
<button class="sb-btn-large" (click)="onAddToGroup()">
<button class="sb-btn-large" (click)="onAddToGroupClick()">
<img src="assets/imgs/ic_person_add_white.svg">
{{'ADD_TO_GROUP' | translate}}
</button>
Expand Down
56 changes: 30 additions & 26 deletions src/app/my-groups/add-member-to-group/add-member-to-group.page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ import {
GroupMemberRole
} from 'sunbird-sdk';
import { Location } from '@angular/common';
import { Router, NavigationExtras } from '@angular/router';
import { RouterLinks, ProfileConstants } from '@app/app/app.constant';
import { Router } from '@angular/router';
import { ProfileConstants } from '@app/app/app.constant';
import { Platform } from '@ionic/angular';
import { AppHeaderService, CommonUtilService } from '@app/services';
import { PopoverController } from '@ionic/angular';
import {animationGrowInTopRight} from '../../animations/animation-grow-in-top-right';
import {animationShrinkOutTopRight} from '../../animations/animation-shrink-out-top-right';
import { animationGrowInTopRight } from '../../animations/animation-grow-in-top-right';
import { animationShrinkOutTopRight } from '../../animations/animation-shrink-out-top-right';
import { MyGroupsPopoverComponent } from '../../components/popups/sb-my-groups-popover/sb-my-groups-popover.component';

@Component({
Expand Down Expand Up @@ -56,13 +56,19 @@ export class AddMemberToGroupPage {
this.commonUtilService.getAppName().then((res) => { this.appName = res; });
}

ionViewWillLeave() {
this.headerObservable.unsubscribe();
if (this.unregisterBackButton) {
this.unregisterBackButton.unsubscribe();
}
}

handleDeviceBackButton() {
this.unregisterBackButton = this.platform.backButton.subscribeWithPriority(10, () => {
this.handleBackButton(false);
});
}


handleHeaderEvents($event) {
switch ($event.name) {
case 'back':
Expand All @@ -81,8 +87,7 @@ export class AddMemberToGroupPage {
}
}

async onVerify() {

async onVerifyClick() {
if (!this.userId) {
this.showErrorMsg = true;
return;
Expand Down Expand Up @@ -114,33 +119,32 @@ export class AddMemberToGroupPage {
this.userId = '';
}

async onAddToGroup() {
async onAddToGroupClick() {
const loader = await this.commonUtilService.getLoader();
await loader.present();
const addMemberToGroupReq: AddMembersRequest = {
groupId: this.groupId,
addMembersRequest: {
members: [{
memberId: this.userDetails.userId,
userId: this.userDetails.userId,
role: GroupMemberRole.MEMBER
}]
},
groupId: this.groupId
}
};
this.groupService.addMembers(addMemberToGroupReq).toPromise().then(async (res) => {
await loader.dismiss();
this.commonUtilService.showToast('MEMBER_ADDED_TO_GROUP');
this.location.back();
}).catch(async (err) => {
await loader.dismiss();
this.commonUtilService.showToast('SOMETHING_WENT_WRONG');
});
}

ionViewWillLeave() {
this.headerObservable.unsubscribe();
if (this.unregisterBackButton) {
this.unregisterBackButton.unsubscribe();
}
this.groupService.addMembers(addMemberToGroupReq).toPromise()
.then(async (res) => {
if (res.errors && res.errors.length) {
throw res.errors[0];
} else {
await loader.dismiss();
this.commonUtilService.showToast('MEMBER_ADDED_TO_GROUP');
this.location.back();
}
}).catch(async (e) => {
console.error(e);
await loader.dismiss();
this.commonUtilService.showToast('SOMETHING_WENT_WRONG');
});
}

async openinfopopup() {
Expand Down
25 changes: 5 additions & 20 deletions src/app/my-groups/create-edit-group/create-edit-group.page.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
import { Subscription } from 'rxjs';
import { Component, Inject, OnDestroy, OnInit } from '@angular/core';
import { Component, Inject } from '@angular/core';
import { Platform, AlertController } from '@ionic/angular';
import { FormBuilder, FormGroup, Validators } from '@angular/forms';
import { TranslateService } from '@ngx-translate/core';
import {
Profile, GroupService, GroupCreateRequest, GroupJoinStrategy, GroupMemberRole
GroupService, GroupCreateRequest, GroupMembershipType
} from 'sunbird-sdk';
import { CommonUtilService } from '@app/services/common-util.service';
import { AppGlobalService } from '@app/services/app-global-service.service';
import { AppHeaderService } from '@app/services/app-header.service';
import { Location } from '@angular/common';

Expand All @@ -16,11 +15,10 @@ import { Location } from '@angular/common';
templateUrl: './create-edit-group.page.html',
styleUrls: ['./create-edit-group.page.scss'],
})
export class CreateEditGroupPage implements OnInit, OnDestroy {
export class CreateEditGroupPage {

appName: string;
createGroupFormSubmitted = false;
profile: Profile;
createGroupForm: FormGroup;
backButtonFunc: Subscription;
hasFilledLocation = false;
Expand All @@ -39,7 +37,6 @@ export class CreateEditGroupPage implements OnInit, OnDestroy {
private commonUtilService: CommonUtilService,
private fb: FormBuilder,
private translate: TranslateService,
private appGlobalService: AppGlobalService,
private headerService: AppHeaderService,
private location: Location,
private platform: Platform,
Expand All @@ -48,14 +45,6 @@ export class CreateEditGroupPage implements OnInit, OnDestroy {
this.initializeForm();
}

ngOnInit() {
this.profile = this.appGlobalService.getCurrentUser();
}

ngOnDestroy() {
// this.formControlSubscriptions.unsubscribe();
}

ionViewWillEnter() {
this.headerService.showHeaderWithBackButton();
this.handleBackButtonEvents();
Expand Down Expand Up @@ -100,17 +89,13 @@ export class CreateEditGroupPage implements OnInit, OnDestroy {
}
}

async createGroup(formVal) {
private async createGroup(formVal) {
const loader = await this.commonUtilService.getLoader();
await loader.present();
const groupCreateRequest: GroupCreateRequest = {
joinStrategy: GroupJoinStrategy.MODERATED,
name: formVal.groupName,
description: formVal.groupDesc,
members: [{
memberId: this.profile.uid,
role: GroupMemberRole.ADMIN
}]
membershipType: GroupMembershipType.MODERATED
};
this.groupService.create(groupCreateRequest).toPromise().then(async (res) => {
await loader.dismiss();
Expand Down
4 changes: 2 additions & 2 deletions src/app/my-groups/group-details/group-details.page.html
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@
<div *ngFor="let member of filteredMemberList; let i = index">
<sb-member-card [config]="{size:'medium', isBold:false, isSelectable:false, view:'horizontal'}"
[identifier]="member.identifier" [indexOfMember]="i"
[initial]="commonUtilService.extractInitial(member.title)" [title]="member.title" [isMenu]="member.isMenu"
[isAdmin]="member.isAdmin" (menuClick)="memberMenuClick($event)">
[initial]="commonUtilService.extractInitial(member.name)" [title]="member.name" [isMenu]="member.isMenu"
[isAdmin]="member.role === 'admin'" (menuClick)="memberMenuClick($event)">
</sb-member-card>
</div>
</div>
Expand Down
Loading

0 comments on commit 187c51c

Please sign in to comment.