diff --git a/src/app/interfaces/git-sync-data.ts b/src/app/interfaces/git-sync-data.ts
new file mode 100644
index 0000000..e63fe89
--- /dev/null
+++ b/src/app/interfaces/git-sync-data.ts
@@ -0,0 +1,5 @@
+export interface GitSyncData {
+ key: string;
+ repo: string;
+ branch: string;
+}
diff --git a/src/app/pages/settings/settings.page.html b/src/app/pages/settings/settings.page.html
index 163abef..34555f6 100644
--- a/src/app/pages/settings/settings.page.html
+++ b/src/app/pages/settings/settings.page.html
@@ -17,30 +17,36 @@
Add a GitHub key to sync with your GitHub repo. You will be able to create tests with DevProbeAI. Get A GitHub Key Here !!!
+
GitHub Key
+
2. Repo Name
Add the name of the repo you want to sync with DevProbeAI.
+
Repo Name
+
3. Branch Name
Add the name of the branch you want to sync with DevProbeAI.
+
Branch Name
+
Sync Repo
diff --git a/src/app/pages/settings/settings.page.ts b/src/app/pages/settings/settings.page.ts
index 2be9958..d186d2d 100644
--- a/src/app/pages/settings/settings.page.ts
+++ b/src/app/pages/settings/settings.page.ts
@@ -1,7 +1,10 @@
import { Component, OnInit } from '@angular/core';
import {AuthService} from "../../services/auth.service";
import {Router} from "@angular/router";
-import {AlertController} from "@ionic/angular";
+import {AlertController, LoadingController} from "@ionic/angular";
+import {GithubService} from "../../services/github.service";
+import {User} from "../../interfaces/user";
+import {GitSyncData} from "../../interfaces/git-sync-data";
@Component({
selector: 'app-settings',
@@ -13,25 +16,63 @@ export class SettingsPage implements OnInit {
repoName: string = '';
branchName: string = '';
+ user: User = {};
+ orgname: string = '';
+
constructor(
private authService:AuthService,
private router:Router,
- private alertCtrl:AlertController
+ private alertCtrl:AlertController,
+ private githubService: GithubService,
+ private loadingCtrl: LoadingController
) { }
ngOnInit() {
}
+ async ionViewWillEnter() {
+
+ //Get User
+ this.user = localStorage.getItem('user') ? JSON.parse(localStorage.getItem('user') || '{}') : null;
+ if (!this.user) {
+ await this.showAlert('No user found', 'Error');
+ return;
+ }
+
+ this.orgname = this.user.orgName || '';
+
+ await this.getSyncRepo();
+ }
+
async logout() {
await this.authService.logoutUser();
await this.router.navigate(['/login']);
}
+ async getSyncRepo() {
+ await this.showLoading();
+
+ const gitSyncData:GitSyncData = await this.githubService.getSyncRepo(this.orgname);
+ if (gitSyncData) {
+ this.gitKey = gitSyncData.key;
+ this.repoName = gitSyncData.repo;
+ this.branchName = gitSyncData.branch;
+ }
+
+ await this.hideLoading();
+ }
+
async syncRepo() {
+ await this.showLoading();
if (!this.gitKey || !this.repoName || !this.branchName || this.gitKey === '' || this.repoName === '' || this.branchName === '') {
await this.showAlert('Please fill in all fields', 'Error');
return;
}
+
+ await this.githubService.syncRepo(this.orgname, this.gitKey, this.repoName, this.branchName);
+
+ await this.hideLoading();
+
}
/**
@@ -48,4 +89,21 @@ export class SettingsPage implements OnInit {
await alert.present();
}
+
+ /**
+ * Show a loading spinner.
+ */
+ async showLoading() {
+ const loading = await this.loadingCtrl.create({
+ });
+ await loading.present();
+ }
+
+ /**
+ * Hide the loading spinner.
+ */
+ async hideLoading() {
+ await this.loadingCtrl.dismiss();
+ }
+
}
diff --git a/src/app/services/github.service.ts b/src/app/services/github.service.ts
new file mode 100644
index 0000000..dc31545
--- /dev/null
+++ b/src/app/services/github.service.ts
@@ -0,0 +1,43 @@
+import { Injectable } from '@angular/core';
+import {doc, Firestore, getDoc, setDoc} from "@angular/fire/firestore";
+import {HttpClient} from "@angular/common/http";
+
+@Injectable({
+ providedIn: 'root'
+})
+export class GithubService {
+
+ constructor(
+ private firestore:Firestore,
+ private httpClient:HttpClient
+ ) { }
+
+ async syncRepo(orgName:string,gitKey: string, repoName: string, branchName: string) {
+ const docRef = doc(this.firestore, 'teams', orgName);
+ const docSnap = await getDoc(docRef);
+
+ if (docSnap.exists()) {
+ const data = docSnap.data();
+ data['gitHub'] = {
+ key: gitKey,
+ repo: repoName,
+ branch: branchName
+ }
+ await setDoc(docRef, data);
+ }
+ }
+
+ async getSyncRepo(orgName:string) {
+ const docRef = doc(this.firestore, 'teams', orgName);
+ const docSnap = await getDoc(docRef);
+
+ if (docSnap.exists()) {
+ const data = docSnap.data();
+ return data['gitHub'];
+ }
+ return null;
+ }
+
+
+
+}
diff --git a/www/1739.8654ca7873a2be68.js b/www/1739.8654ca7873a2be68.js
new file mode 100644
index 0000000..76f3686
--- /dev/null
+++ b/www/1739.8654ca7873a2be68.js
@@ -0,0 +1 @@
+"use strict";(self.webpackChunkapp=self.webpackChunkapp||[]).push([[1739],{5553:(b,m,i)=>{i.d(m,{h:()=>h});var y=i(177),d=i(7863),a=i(4438);let h=(()=>{var s;class e{}return(s=e).\u0275fac=function(u){return new(u||s)},s.\u0275mod=a.$C({type:s}),s.\u0275inj=a.G2t({imports:[y.MD,d.bv]}),e})()},1739:(b,m,i)=>{i.r(m),i.d(m,{SettingsPageModule:()=>j});var y=i(177),d=i(4341),a=i(7863),h=i(7650),s=i(467),e=i(4438),f=i(4796),u=i(4262),P=i(1626);let R=(()=>{var o;class c{constructor(t,n){this.firestore=t,this.httpClient=n}syncRepo(t,n,l,r){var p=this;return(0,s.A)(function*(){const S=(0,u.H9)(p.firestore,"teams",t),v=yield(0,u.x7)(S);if(v.exists()){const M=v.data();M.gitHub={key:n,repo:l,branch:r},yield(0,u.BN)(S,M)}})()}getSyncRepo(t){var n=this;return(0,s.A)(function*(){const l=(0,u.H9)(n.firestore,"teams",t),r=yield(0,u.x7)(l);return r.exists()?r.data().gitHub:null})()}}return(o=c).\u0275fac=function(t){return new(t||o)(e.KVO(u._7),e.KVO(P.Qq))},o.\u0275prov=e.jDH({token:o,factory:o.\u0275fac,providedIn:"root"}),c})();var C=i(385),F=i(8453);const E=[{path:"",component:(()=>{var o;class c{constructor(t,n,l,r,p){this.authService=t,this.router=n,this.alertCtrl=l,this.githubService=r,this.loadingCtrl=p,this.gitKey="",this.repoName="",this.branchName="",this.user={},this.orgname=""}ngOnInit(){}ionViewWillEnter(){var t=this;return(0,s.A)(function*(){t.user=localStorage.getItem("user")?JSON.parse(localStorage.getItem("user")||"{}"):null,t.user?(t.orgname=t.user.orgName||"",yield t.getSyncRepo()):yield t.showAlert("No user found","Error")})()}logout(){var t=this;return(0,s.A)(function*(){yield t.authService.logoutUser(),yield t.router.navigate(["/login"])})()}getSyncRepo(){var t=this;return(0,s.A)(function*(){yield t.showLoading();const n=yield t.githubService.getSyncRepo(t.orgname);n&&(t.gitKey=n.key,t.repoName=n.repo,t.branchName=n.branch),yield t.hideLoading()})()}syncRepo(){var t=this;return(0,s.A)(function*(){yield t.showLoading(),t.gitKey&&t.repoName&&t.branchName&&""!==t.gitKey&&""!==t.repoName&&""!==t.branchName?(yield t.githubService.syncRepo(t.orgname,t.gitKey,t.repoName,t.branchName),yield t.hideLoading()):yield t.showAlert("Please fill in all fields","Error")})()}showAlert(t,n){var l=this;return(0,s.A)(function*(){yield(yield l.alertCtrl.create({header:n,message:t,buttons:["OK"]})).present()})()}showLoading(){var t=this;return(0,s.A)(function*(){yield(yield t.loadingCtrl.create({})).present()})()}hideLoading(){var t=this;return(0,s.A)(function*(){yield t.loadingCtrl.dismiss()})()}}return(o=c).\u0275fac=function(t){return new(t||o)(e.rXU(f.u),e.rXU(h.Ix),e.rXU(a.hG),e.rXU(R),e.rXU(a.Xi))},o.\u0275cmp=e.VBU({type:o,selectors:[["app-settings"]],decls:49,vars:7,consts:[[3,"title"],[3,"fullscreen"],[1,"lg:m-10","md:m-10"],["size","12","size-md","12","size-lg","12",1,"flex","flex-row","justify-center"],["color","danger",1,"min-w-full",3,"click"],["size","12","size-md","12","size-lg","12",1,""],[1,"p-5"],[1,"text-2xl"],[1,"text-white"],["href","https://github.com/settings/tokens",1,"text-blue-500"],["placeholder","Enter your key here...",1,"text-white",3,"ngModelChange","ngModel"],["placeholder","Enter your repo name here...",1,"text-white",3,"ngModelChange","ngModel"],["placeholder","Enter your branch name here...",1,"text-white",3,"ngModelChange","ngModel"],["color","primary",1,"min-w-full",3,"click"]],template:function(t,n){1&t&&(e.nrm(0,"app-header",0),e.j41(1,"ion-content",1)(2,"ion-grid"),e.nrm(3,"app-title",0),e.j41(4,"ion-row",2)(5,"ion-col",3)(6,"ion-button",4),e.bIt("click",function(){return n.logout()}),e.EFF(7,"Logout"),e.k0s()()(),e.nrm(8,"app-title",0),e.j41(9,"ion-row",2)(10,"ion-col",5)(11,"ion-card",6)(12,"ion-card",6)(13,"ion-card-title",7),e.EFF(14,"1. Add a GitHub Key"),e.k0s(),e.j41(15,"ion-card-content")(16,"p",8),e.EFF(17," Add a GitHub key to sync with your GitHub repo. You will be able to create tests with DevProbeAI. "),e.j41(18,"a",9),e.EFF(19,"Get A GitHub Key Here !!!"),e.k0s()()(),e.j41(20,"ion-card")(21,"ion-card-content")(22,"ion-label"),e.EFF(23,"GitHub Key"),e.k0s(),e.j41(24,"ion-input",10),e.mxI("ngModelChange",function(r){return e.DH7(n.gitKey,r)||(n.gitKey=r),r}),e.k0s()()()(),e.j41(25,"ion-card",6)(26,"ion-card-title",7),e.EFF(27,"2. Repo Name"),e.k0s(),e.j41(28,"ion-card-content")(29,"p",8),e.EFF(30," Add the name of the repo you want to sync with DevProbeAI. "),e.k0s()(),e.j41(31,"ion-card")(32,"ion-card-content")(33,"ion-label"),e.EFF(34,"Repo Name"),e.k0s(),e.j41(35,"ion-input",11),e.mxI("ngModelChange",function(r){return e.DH7(n.repoName,r)||(n.repoName=r),r}),e.k0s()()()(),e.j41(36,"ion-card",6)(37,"ion-card-title",7),e.EFF(38,"3. Branch Name"),e.k0s(),e.j41(39,"ion-card-content")(40,"p",8),e.EFF(41," Add the name of the branch you want to sync with DevProbeAI. "),e.k0s()(),e.j41(42,"ion-card")(43,"ion-card-content")(44,"ion-label"),e.EFF(45,"Branch Name"),e.k0s(),e.j41(46,"ion-input",12),e.mxI("ngModelChange",function(r){return e.DH7(n.branchName,r)||(n.branchName=r),r}),e.k0s()()()(),e.j41(47,"ion-button",13),e.bIt("click",function(){return n.syncRepo()}),e.EFF(48,"Sync Repo"),e.k0s()()()()()()),2&t&&(e.Y8G("title","Settings"),e.R7$(),e.Y8G("fullscreen",!0),e.R7$(2),e.Y8G("title","Account SingOut"),e.R7$(5),e.Y8G("title","Sync GitHub Repo"),e.R7$(16),e.R50("ngModel",n.gitKey),e.R7$(11),e.R50("ngModel",n.repoName),e.R7$(11),e.R50("ngModel",n.branchName))},dependencies:[d.BC,d.vS,a.Jm,a.b_,a.I9,a.tN,a.hU,a.W9,a.lO,a.$w,a.he,a.ln,a.Gw,C.l,F.W]}),c})()}];let N=(()=>{var o;class c{}return(o=c).\u0275fac=function(t){return new(t||o)},o.\u0275mod=e.$C({type:o}),o.\u0275inj=e.G2t({imports:[h.iI.forChild(E),h.iI]}),c})();var A=i(5553);let j=(()=>{var o;class c{}return(o=c).\u0275fac=function(t){return new(t||o)},o.\u0275mod=e.$C({type:o}),o.\u0275inj=e.G2t({imports:[y.MD,d.YN,a.bv,N,A.h]}),c})()}}]);
\ No newline at end of file
diff --git a/www/5371.515dd459725fd404.js b/www/5371.515dd459725fd404.js
deleted file mode 100644
index cd665ca..0000000
--- a/www/5371.515dd459725fd404.js
+++ /dev/null
@@ -1 +0,0 @@
-"use strict";(self.webpackChunkapp=self.webpackChunkapp||[]).push([[5371],{5553:(f,h,o)=>{o.d(h,{h:()=>d});var m=o(177),c=o(7863),i=o(4438);let d=(()=>{var l;class e{}return(l=e).\u0275fac=function(y){return new(y||l)},l.\u0275mod=i.$C({type:l}),l.\u0275inj=i.G2t({imports:[m.MD,c.bv]}),e})()},5371:(f,h,o)=>{o.r(h),o.d(h,{SettingsPageModule:()=>v});var m=o(177),c=o(4341),i=o(7863),d=o(7650),l=o(467),e=o(4438),p=o(4796),y=o(385),M=o(8453);const P=[{path:"",component:(()=>{var n;class s{constructor(t,a,g){this.authService=t,this.router=a,this.alertCtrl=g,this.gitKey="",this.repoName="",this.branchName=""}ngOnInit(){}logout(){var t=this;return(0,l.A)(function*(){yield t.authService.logoutUser(),yield t.router.navigate(["/login"])})()}syncRepo(){var t=this;return(0,l.A)(function*(){t.gitKey&&t.repoName&&t.branchName&&""!==t.gitKey&&""!==t.repoName&&""!==t.branchName||(yield t.showAlert("Please fill in all fields","Error"))})()}showAlert(t,a){var g=this;return(0,l.A)(function*(){yield(yield g.alertCtrl.create({header:a,message:t,buttons:["OK"]})).present()})()}}return(n=s).\u0275fac=function(t){return new(t||n)(e.rXU(p.u),e.rXU(d.Ix),e.rXU(i.hG))},n.\u0275cmp=e.VBU({type:n,selectors:[["app-settings"]],decls:46,vars:7,consts:[[3,"title"],[3,"fullscreen"],[1,"lg:m-10","md:m-10"],["size","12","size-md","12","size-lg","12",1,"flex","flex-row","justify-center"],["color","danger",1,"min-w-full",3,"click"],["size","12","size-md","12","size-lg","12",1,""],[1,"p-5"],[1,"text-2xl"],[1,"text-white"],["href","https://github.com/settings/tokens",1,"text-blue-500"],["placeholder","Enter your key here...",1,"text-white",3,"ngModelChange","ngModel"],["placeholder","Enter your repo name here...",1,"text-white",3,"ngModelChange","ngModel"],["placeholder","Enter your branch name here...",1,"text-white",3,"ngModelChange","ngModel"],["color","primary",1,"min-w-full",3,"click"]],template:function(t,a){1&t&&(e.nrm(0,"app-header",0),e.j41(1,"ion-content",1)(2,"ion-grid"),e.nrm(3,"app-title",0),e.j41(4,"ion-row",2)(5,"ion-col",3)(6,"ion-button",4),e.bIt("click",function(){return a.logout()}),e.EFF(7,"Logout"),e.k0s()()(),e.nrm(8,"app-title",0),e.j41(9,"ion-row",2)(10,"ion-col",5)(11,"ion-card",6)(12,"ion-card",6)(13,"ion-card-title",7),e.EFF(14,"1. Add a GitHub Key"),e.k0s(),e.j41(15,"ion-card-content")(16,"p",8),e.EFF(17," Add a GitHub key to sync with your GitHub repo. You will be able to create tests with DevProbeAI. "),e.j41(18,"a",9),e.EFF(19,"Get A GitHub Key Here !!!"),e.k0s()()(),e.j41(20,"ion-card-content")(21,"ion-label"),e.EFF(22,"GitHub Key"),e.k0s(),e.j41(23,"ion-input",10),e.mxI("ngModelChange",function(r){return e.DH7(a.gitKey,r)||(a.gitKey=r),r}),e.k0s()()(),e.j41(24,"ion-card",6)(25,"ion-card-title",7),e.EFF(26,"2. Repo Name"),e.k0s(),e.j41(27,"ion-card-content")(28,"p",8),e.EFF(29," Add the name of the repo you want to sync with DevProbeAI. "),e.k0s()(),e.j41(30,"ion-card-content")(31,"ion-label"),e.EFF(32,"Repo Name"),e.k0s(),e.j41(33,"ion-input",11),e.mxI("ngModelChange",function(r){return e.DH7(a.repoName,r)||(a.repoName=r),r}),e.k0s()()(),e.j41(34,"ion-card",6)(35,"ion-card-title",7),e.EFF(36,"3. Branch Name"),e.k0s(),e.j41(37,"ion-card-content")(38,"p",8),e.EFF(39," Add the name of the branch you want to sync with DevProbeAI. "),e.k0s()(),e.j41(40,"ion-card-content")(41,"ion-label"),e.EFF(42,"Branch Name"),e.k0s(),e.j41(43,"ion-input",12),e.mxI("ngModelChange",function(r){return e.DH7(a.branchName,r)||(a.branchName=r),r}),e.k0s()()(),e.j41(44,"ion-button",13),e.bIt("click",function(){return a.syncRepo()}),e.EFF(45,"Sync Repo"),e.k0s()()()()()()),2&t&&(e.Y8G("title","Settings"),e.R7$(),e.Y8G("fullscreen",!0),e.R7$(2),e.Y8G("title","Account SingOut"),e.R7$(5),e.Y8G("title","Sync GitHub Repo"),e.R7$(15),e.R50("ngModel",a.gitKey),e.R7$(10),e.R50("ngModel",a.repoName),e.R7$(10),e.R50("ngModel",a.branchName))},dependencies:[c.BC,c.vS,i.Jm,i.b_,i.I9,i.tN,i.hU,i.W9,i.lO,i.$w,i.he,i.ln,i.Gw,y.l,M.W]}),s})()}];let F=(()=>{var n;class s{}return(n=s).\u0275fac=function(t){return new(t||n)},n.\u0275mod=e.$C({type:n}),n.\u0275inj=e.G2t({imports:[d.iI.forChild(P),d.iI]}),s})();var S=o(5553);let v=(()=>{var n;class s{}return(n=s).\u0275fac=function(t){return new(t||n)},n.\u0275mod=e.$C({type:n}),n.\u0275inj=e.G2t({imports:[m.MD,c.YN,i.bv,F,S.h]}),s})()}}]);
\ No newline at end of file
diff --git a/www/index.html b/www/index.html
index b9182a2..965d0bd 100644
--- a/www/index.html
+++ b/www/index.html
@@ -21,6 +21,6 @@
-
+