Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cria função para verificar se há planos na escola a serem renderizados #3

Open
wants to merge 1 commit into
base: 1.1
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions src/pages/teaching-plan-index/teaching-plan-index.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,16 @@
</ion-header>

<ion-content class="page-content" padding>
<div *ngIf="unities.length && unities[0].teachingPlans.length" class="accordion-list-border accordion-teaching-plan">
<div *ngIf="unities.length && hasTeachingPlans()" class="accordion-list-border accordion-teaching-plan">
<ion-list class="accordion-list"
*ngFor="let unity of unities; let i=index">
<ion-list-header class="accordion-list-header accordion-list-header-teaching"
<ion-list-header class="accordion-list-header
accordion-list-header-teaching"
no-lines
text-wrap
(click)="toggleGroup(i)"
[ngClass]="{active: isGroupShown(i)}">
<p class="unity_name">{{unity.name}}</p>
<p class="unity_name"> {{unity.name}}</p>
</ion-list-header>

<div *ngFor="let teachingPlan of unity.teachingPlans;">
Expand All @@ -29,7 +30,7 @@
</div>
</ion-list>
</div>
<div *ngIf="!unities.length || (unities[0] && !unities[0].teachingPlans.length)" class="empty-results">
<div *ngIf="!unities.length && !hasTeachingPlans()" class="empty-results">
<p margin>Nenhum plano de ensino foi encontrado.</p>
</div>
</ion-content>
28 changes: 19 additions & 9 deletions src/pages/teaching-plan-index/teaching-plan-index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,12 @@ import { SyncProvider } from '../../services/sync';
})
export class TeachingPlanIndexPage {
shownGroup = null;

unities = [];

constructor(public navCtrl: NavController,
public navParams: NavParams,
private sync: SyncProvider,
private storage: Storage
) {
private storage: Storage) {
}

ionViewDidLoad() {
Expand All @@ -36,27 +34,39 @@ export class TeachingPlanIndexPage {
teachingPlans.unities.forEach(unity => {
let teachingPlans = [];
unity.plans.forEach(plan => {
teachingPlans.push({ id: plan.id,
description: plan.description + ' - ' + plan.grade_name });
teachingPlans.push({
id: plan.id,
description: plan.description + ' - ' + plan.grade_name
});
});
this.unities.push({ name: unity.unity_name, teachingPlans: teachingPlans});
this.unities.push({ name: unity.unity_name, teachingPlans: teachingPlans });
});
});
}

toggleGroup(group) {
if (this.isGroupShown(group)) {
this.shownGroup = null;
this.shownGroup = null;
} else {
this.shownGroup = group;
this.shownGroup = group;
}
};

isGroupShown(group) {
return this.shownGroup === group;
return this.shownGroup === group;
};

openDetail(teachingPlanId) {
this.navCtrl.push(TeachingPlanDetailsPage, { "teachingPlanId": teachingPlanId });
}

hasTeachingPlans(): boolean {
let hasPlans = false;
this.unities.forEach(unity => {
if (unity.teachingPlans && unity.teachingPlans.length > 0) {
hasPlans = true;
}
});
return hasPlans;
}
Comment on lines +63 to +71

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Essa lógica não vai causar problema? 🤔

O que aconteceria se a primeira unidade tiver teachingPlans e a última não?

Se for para não mostrar as unidades que não tem teachingPlans, eu colocaria a condicional dentro do ngFor.

}