Skip to content

Commit

Permalink
all functions ok
Browse files Browse the repository at this point in the history
  • Loading branch information
anthonycros committed Jan 19, 2022
1 parent ab65ebe commit fcf1d45
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 47 deletions.
33 changes: 12 additions & 21 deletions src/app/channel-details/channel-details.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,18 +36,22 @@ export class ChannelDetailsComponent implements OnInit {
if (channelIdFromRoute == "new") {
console.log(`On est dans une création de channel`)
this.context_mode = "new";
let localNb;
//test pour générer nouvel ID
let localChannels: Channel[];
console.log(`On entre dans le calcul de l'id`);
this.channelService.getChannelsApi().then(resultat=> {
localChannels = resultat });
localNb = this.channelService.genChannelId(localChannels);
let localNb;
console.log('On entre dans le calcul du genid');
this.channelService.getChannels().then(autreresultat=> {
localChannels = autreresultat;
console.log(`localChannels[0].name vaut : ${localChannels[0].name}`);
console.log(`localChannels.lenght vaut : ${localChannels.length}`);
localNb = this.channelService.genChannelId(localChannels);
console.log(`L'id récupéré vaut : ${localNb}`)

this.channel = {id: localNb, name: "", url: ""};
}
this.channel = {id: localNb, name: "", url: ""};
})}
else
{
this.channelService.getChannelsApi().then(resultat=>
this.channelService.getChannels().then(resultat=>
{
this.context_mode = "update";
this.channel = resultat.find(channel => channel.id === Number(channelIdFromRoute)) ;
Expand All @@ -59,12 +63,6 @@ export class ChannelDetailsComponent implements OnInit {
this.location.back();
}

save(): void {
if (this.channel) {
this.channelService.updateChannel(this.channel).subscribe(()=> this.goBack())
}
}

//Todo : corriger le goback apres update
onSubmit() {
this.submitted = true;
Expand All @@ -73,13 +71,6 @@ export class ChannelDetailsComponent implements OnInit {
this.channelService.updateChannel(this.channel).subscribe(() => this.goBack());
}
else if (this.context_mode == "new") {







this.channelService.createChannel(this.channel).subscribe(() => this.goBack());
}
}
Expand Down
24 changes: 4 additions & 20 deletions src/app/channel-list/channel-list.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,51 +10,35 @@ import { ChannelService } from '../channel.service';
export class ChannelListComponent implements OnInit {

//channel: Channel;
channels = this.channelService.getChannelsApi();
channels = this.channelService.getChannels();
channelstemp: Channel[];
channelstempApi: Channel[];


constructor(private channelService: ChannelService) { }

ngOnInit(): void {

}

delete(channel: Channel) {
console.log(`Appel de la fonction delete sur la chaîne dont l'id est : ${channel.id}`);
//console.log(`Appel de la fonction delete sur la chaîne dont l'id est : ${channel.id}`);
if (channel) {
this.channelService.deleteChannel(channel.id).subscribe()
}

}

newchannel () {
console.log('bonjour');
this.channelService.getChannelsApi().then(resultat=> {
console.log('Appel de new channel dans channel list');
this.channelService.getChannels().then(resultat=> {
this.channelstemp = resultat
})
let nb = this.channelService.genChannelId(this.channelstemp)
console.log(`antho en direct dit : ${nb}`)
window.alert(`antho en direct dit : ${nb}`)
};

// delete(channel: Channel): void {
// channel = this.channels.filter(h => h !== channel);
// this.channelService.deleteRecord(channel.id).subscribe();
// }

test_anthoApi () {
let localChannels: Channel[];
let localNb: Number;
console.log('On entre dans test_anthoapi');
this.channelService.getChannelsApi().then(autreresultat=> {
localChannels = autreresultat;
console.log(`localChannels[0].name vaut : ${localChannels[0].name}`);
console.log(`localChannels.lenght vaut : ${localChannels.length}`);
localNb = this.channelService.genChannelId(localChannels);
console.log(`antho via API dit : ${localNb}`)
})
};


Expand Down
2 changes: 1 addition & 1 deletion src/app/channel.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export class ChannelService {
};

// Récupération de la liste des chaînes
getChannelsApi():Promise <Array<Channel>> {
getChannels():Promise <Array<Channel>> {
return new Promise((resolve, reject)=>
{
this.http.get<Array<Channel>>(`${this.channelUrl}/list`).subscribe(resultat=>{ resolve(resultat) });
Expand Down
6 changes: 1 addition & 5 deletions src/app/record-details/record-details.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export class RecordDetailsComponent implements OnInit {
this.targetChannelid = this.record.idch
})

this.channelService.getChannelsApi().then(resultat=>
this.channelService.getChannels().then(resultat=>
{
this.channels = resultat
})
Expand All @@ -59,9 +59,5 @@ export class RecordDetailsComponent implements OnInit {
const chosenChannel = this.channels.find((element: Channel)=>{return element.id==this.targetChannelid});
this.record.idch = chosenChannel.id
this.record.urlch = chosenChannel.url
//console.log(this.targetChannelid)


}

}

0 comments on commit fcf1d45

Please sign in to comment.