Skip to content

Commit

Permalink
Update fixed all the deletion backend issues and the contacts page po…
Browse files Browse the repository at this point in the history
…pover issue
  • Loading branch information
maheedhar1998 committed Mar 4, 2020
1 parent 47e5afa commit 7011934
Show file tree
Hide file tree
Showing 16 changed files with 775 additions and 48 deletions.
618 changes: 598 additions & 20 deletions package-lock.json

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
"@ionic-native/splash-screen": "^5.0.0",
"@ionic-native/status-bar": "^5.19.1",
"@ionic/angular": "^4.7.1",
"@ionic/cli": "^6.1.0",
"call-number": "^1.0.1",
"cordova": "^9.0.0",
"cordova-android": "^8.1.0",
Expand Down
1 change: 1 addition & 0 deletions src/app/app-routing.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ const routes: Routes = [
{ path: 'profile', loadChildren: './profile/profile.module#ProfilePageModule' }, { path: 'settings', loadChildren: './settings/settings.module#SettingsPageModule' },
{ path: 'super-tabs', loadChildren: './super-tabs/super-tabs.module#SuperTabsPageModule' },
{ path: 'user-contact', loadChildren: './user-contact/user-contact.module#UserContactPageModule' },
{ path: 'popover-other', loadChildren: './popover-other/popover-other.module#PopoverOtherPageModule' },

];

Expand Down
1 change: 1 addition & 0 deletions src/app/contacts/contacts.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { ContactsPage } from './contacts.page';
const routes: Routes = [
{
path: '',
component: ContactsPage
}
];

Expand Down
2 changes: 1 addition & 1 deletion src/app/contacts/contacts.page.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
</ion-item>
<ion-item-options side="end">
<ion-item-option color="danger" (click)="deleteAccount(account)">
<ion-icon color="dark" name="trash"></ion-icon>
<ion-icon color="dark" style="font-size: 150%;" name="trash"></ion-icon>
</ion-item-option>
</ion-item-options>
</ion-item-sliding>
Expand Down
1 change: 1 addition & 0 deletions src/app/contacts/contacts.page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ export class ContactsPage implements OnInit {
}

deleteAccount(account: backend.socialAccount) {
console.log(account);
this.firebase.deleteSocialAccount(this.type, account);
}

Expand Down
73 changes: 57 additions & 16 deletions src/app/firebase-backend.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export class FirebaseBackendService {
// Send users data to firebse and sets in the way desribed by architecture milestone
public sendUserDataSignUp(name_user: string, username_user: string, email_user: string, phoneNumber_user: string, dateOfBirth: Date, photo_user: string, uid: string ) {
this.uid = uid;
var user: backend.user = new backend.user(this.uid, name_user, username_user, email_user, phoneNumber_user, dateOfBirth, photo_user, null, null, null);
var user: backend.user = new backend.user(this.uid, name_user, username_user, email_user, phoneNumber_user, dateOfBirth, photo_user, null, null, [new backend.qrCode(null, new backend.contact(null,username_user,name_user,email_user,phoneNumber_user,dateOfBirth,photo_user,null))]);
console.log(this.uid);
console.log(user);
firebase.database().ref('Users/'+this.uid).set(user).then((res) => {
Expand Down Expand Up @@ -52,11 +52,15 @@ export class FirebaseBackendService {
}
// deletion from user contact list
async deleteFromUserContacts(cont: backend.contact) {
var userContacts: backend.contact [];
console.log(cont);
var userContacts: {} [];
await this.getUserData().then(usr => {
userContacts = usr.getContacts;
for(let i: number = 0; i < userContacts.length; i++){
if(userContacts[i].isEqual(cont)){
if(userContacts[i]['id'] == cont['id'] && userContacts[i]['name'] == cont['name'] && userContacts[i]['username'] == userContacts[i]['username'] && userContacts[i]['email'] == cont['email']
&& userContacts[i]['phoneNumber'] == cont['phoneNumber'] && userContacts[i]['DOB'] == cont['DOB'] && userContacts[i]['photo'] == cont['photo'])
{
console.log(userContacts);
userContacts.splice(i,1);
break;
}
Expand Down Expand Up @@ -89,39 +93,76 @@ export class FirebaseBackendService {
}
// delete social account
async deleteSocialAccount(typ: string, sAcot: backend.socialAccount) {
var userSocialAccounts: backend.socialAccount [];
var userSocialAccounts: {} [];
var userSocials: {} [] = [];
let i:number = 0;
for(; i < userSocials.length; i++){
if(userSocials[i]['type'] == typ){
break;
}
}
await this.getUserData().then(usr => {
userSocials = usr.getSocials;
this.getSocialAccountsType(typ).then(dat => {
userSocialAccounts = dat;
for(let i:number = 0; i < userSocialAccounts.length; i++){
if(userSocialAccounts[i].isEqual(sAcot)){
console.log(userSocialAccounts[i]);
if(userSocialAccounts[i]['id'] == sAcot['id'] && userSocialAccounts[i]['user'] == sAcot['user'] && userSocialAccounts[i]['url'] == sAcot['url']){
userSocialAccounts.splice(i,1);
break;
}
}
var updates = {};
userSocials[i]['socialAccounts'] = userSocialAccounts;
// console.log(userSocials[i]);
updates['Users/'+this.uid+'/socials'] = userSocials;
firebase.database().ref().update(updates);
});
let i:number = 0;
for(; i < userSocials.length; i++){
if(userSocials[i]['type'] == typ){
break;
}
}
var updates = {};
updates['Users/'+this.uid+'/socials/'+i+'/socialAccount'] = userSocialAccounts;
firebase.database().ref().update(updates);
});
}
// Getting social accounts of a given type
async getSocialAccountsType(type: string) : Promise<backend.socialAccount []> {
console.log(type)
// console.log(type)
var socialAccs: backend.socialAccount[];
await this.getUserData().then(usr => {
let found: boolean = false;
let socials: {}[] = usr.getSocials;
for(let i: number = 0; i<socials.length && !found; i++) {
console.log(socials[i]);
// console.log(socials[i]);
if(socials[i]['type'] == type) {
socialAccs = socials[i]['socialAccounts'];
found = true;
}
}
if(!found){
socialAccs = [new backend.socialAccount(null,null,null)];
}
});
return socialAccs;
}
// Gets a contacts accessible socials
async getContactAccessSocials(usrName: string): Promise<backend.social []> {
var qrCodes: {} [] = [];
var accessSocials: backend.social[] = [];
await this.getUserData().then(usr => {
qrCodes = usr.getQrCodes;
for(let i: number = 0; i<qrCodes.length; i++) {
if(qrCodes[i]['qContact']['username'] == usrName) {
accessSocials.push(qrCodes[i]['qContact']['accessSocials']);
}
}
});
return accessSocials;
}
// Gets social accounts of a type from a contact
async getSocialAccountsTypeContact(type: string, usrName: string) : Promise<backend.socialAccount []> {
// console.log(type)
var socialAccs: backend.socialAccount[];
await this.getContactAccessSocials(usrName).then(usr => {
let found: boolean = false;
let socials: {} [] = usr;
for(let i: number = 0; i<socials.length && !found; i++) {
// console.log(socials[i]);
if(socials[i]['type'] == type) {
socialAccs = socials[i]['socialAccounts'];
found = true;
Expand Down
2 changes: 1 addition & 1 deletion src/app/home/home.page.html
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
</ion-item>
<ion-item-options side="end">
<ion-item-option color="danger" (click)="deleteContact(contact)">
<ion-icon color="dark" name="trash"></ion-icon>
<ion-icon color="dark" style="font-size: 150%;" name="trash"></ion-icon>
</ion-item-option>
</ion-item-options>
</ion-item-sliding>
Expand Down
1 change: 1 addition & 0 deletions src/app/home/home.page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ export class HomePage {
}

deleteContact(cont: backend.contact) {
// console.log(cont);
this.firebase.deleteFromUserContacts(cont);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@ import { Routes, RouterModule } from '@angular/router';

import { IonicModule } from '@ionic/angular';

import { ContactsPage } from './contacts.page';
import { PopoverOtherPage } from './popover-other.page';

const routes: Routes = [
{
path: '',
component: PopoverOtherPage
}
];

Expand All @@ -20,7 +21,6 @@ const routes: Routes = [
IonicModule,
RouterModule.forChild(routes)
],
declarations: [],
exports: [ContactsPage]
declarations: [PopoverOtherPage]
})
export class Contacts2PageModule {}
export class PopoverOtherPageModule {}
17 changes: 17 additions & 0 deletions src/app/popover-other/popover-other.page.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<ion-content>
<ion-card>
<ion-card-title>{{type}}</ion-card-title>
<ion-list *ngIf="!none">
<ion-item-sliding *ngFor="let account of socialAccounts">
<ion-item>
<ion-label>{{account.user}}</ion-label>
</ion-item>
<ion-item-options side="end">
<ion-item-option color="danger" (click)="deleteAccount(account)">
<ion-icon color="dark" style="font-size: 150%;" name="trash"></ion-icon>
</ion-item-option>
</ion-item-options>
</ion-item-sliding>
</ion-list>
</ion-card>
</ion-content>
7 changes: 7 additions & 0 deletions src/app/popover-other/popover-other.page.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
ion-content {
padding: 0px;
}
ion-card {
padding: 0px;
text-align: center;
}
27 changes: 27 additions & 0 deletions src/app/popover-other/popover-other.page.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { CUSTOM_ELEMENTS_SCHEMA } from '@angular/core';
import { async, ComponentFixture, TestBed } from '@angular/core/testing';

import { PopoverOtherPage } from './popover-other.page';

describe('PopoverOtherPage', () => {
let component: PopoverOtherPage;
let fixture: ComponentFixture<PopoverOtherPage>;

beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [ PopoverOtherPage ],
schemas: [CUSTOM_ELEMENTS_SCHEMA],
})
.compileComponents();
}));

beforeEach(() => {
fixture = TestBed.createComponent(PopoverOtherPage);
component = fixture.componentInstance;
fixture.detectChanges();
});

it('should create', () => {
expect(component).toBeTruthy();
});
});
52 changes: 52 additions & 0 deletions src/app/popover-other/popover-other.page.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import { Component, OnInit } from '@angular/core';
import { Router } from '@angular/router'
import * as backend from '../backendClasses';
import { FirebaseBackendService } from '../firebase-backend.service';
import * as firebase from 'firebase';
import { NavParams } from '@ionic/angular';

@Component({
selector: 'app-popover-other',
templateUrl: './popover-other.page.html',
styleUrls: ['./popover-other.page.scss'],
})
export class PopoverOtherPage implements OnInit {
private firebase: FirebaseBackendService;
private type: string;
private username: string;
private socialAccounts: backend.socialAccount[];
private none: boolean;
constructor(private router: Router, private navParam: NavParams) {
this.none = false;
firebase.auth().onAuthStateChanged(firebaseUser => {
if(!firebaseUser)
{
this.router.navigate(['login']);
}
else
{
this.firebase = new FirebaseBackendService(firebase.auth().currentUser.uid);
this.type = this.navParam.get('type');
this.username = this.navParam.get('username');
this.firebase.getSocialAccountsTypeContact(this.type, this.username).then(socialsArr => {
this.socialAccounts = socialsArr;
if(this.socialAccounts.length == 1
&& this.socialAccounts[0].getId == "N/A"
&& this.socialAccounts[0].getUrl == "N/A"
&& this.socialAccounts[0].getUser == "N/A") {
this.socialAccounts = [];
this.none = true;
}
console.log(socialsArr);
});
}
});
}

ngOnInit() {
}

goToHome() {
this.router.navigate(['home']);
}
}
7 changes: 3 additions & 4 deletions src/app/user-contact/user-contact.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { Routes, RouterModule } from '@angular/router';
import { IonicModule } from '@ionic/angular';

import { UserContactPage } from './user-contact.page';
// import { Contacts2PageModule } from '../contacts/contacts2.module';
import { PopoverOtherPage } from '../popover-other/popover-other.page';

const routes: Routes = [
{
Expand All @@ -24,9 +24,8 @@ const routes: Routes = [
],
declarations: [
UserContactPage,
// Contacts2PageModule
PopoverOtherPage
],
entryComponents: [//Contacts2PageModule
]
entryComponents: [PopoverOtherPage]
})
export class UserContactPageModule {}
5 changes: 3 additions & 2 deletions src/app/user-contact/user-contact.page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { Router, ActivatedRoute } from '@angular/router';
import * as backend from '../backendClasses';
import { PopoverController } from '@ionic/angular';
import { ContactsPage } from '../contacts/contacts.page';
import { PopoverOtherPage } from '../popover-other/popover-other.page';

@Component({
selector: 'app-user-contact',
Expand Down Expand Up @@ -43,8 +44,8 @@ export class UserContactPage implements OnInit {

async openPopover(ev: any, typ: string) {
const pop = await this.popOver.create({
component: ContactsPage,
componentProps: {'type': typ},
component: PopoverOtherPage,
componentProps: {'type': typ, 'username': this.profile.getUsername},
translucent: true,
backdropDismiss: true,
cssClass: 'popover',
Expand Down

0 comments on commit 7011934

Please sign in to comment.