Browse Source

adapt store actions

master
Felix Diemar 4 years ago
parent
commit
e75e22316e

+ 7
- 4
app/components/produkt.hbs View File

<h3>{{@produkt.titel}}</h3> <h3>{{@produkt.titel}}</h3>
<ul class="details"> <ul class="details">
<li class="detail"><h4>Menge:</h4> {{@produkt.menge}}{{@produkt.einheit}}</li> <li class="detail"><h4>Menge:</h4> {{@produkt.menge}}{{@produkt.einheit}}</li>
<!--<li class="detail"><h4>this.ex:</h4> {{this.ex}}</li>
<li class="detail"><h4>this.prodn:</h4> {{this.prodn}}</li>
<li class="detail"><h4>produkt count:</h4> {{this.count}}</li>-->
</ul> </ul>
</div> </div>
</button>
</button>



<!--<li class="detail"><h4>this.ex:</h4> {{this.ex}}</li>
<li class="detail"><h4>this.prodn:</h4> {{this.prodn}}</li>
<li class="detail"><h4>produkt count:</h4> {{this.count}}</li>-->

+ 7
- 29
app/components/produkt.js View File

export default class ProduktController extends Component { export default class ProduktController extends Component {
@tracked isLarge = false; @tracked isLarge = false;
@tracked isSelected = false; @tracked isSelected = false;
@tracked ex = false;
@tracked isSet = false;
@tracked prodn = "test";
@tracked count = 0;
@service store; @service store;




@action getStatus(produktname) @action getStatus(produktname)
{ {
this.prodn = produktname;

this.store.findAll('produkt') this.store.findAll('produkt')
.then(function(suchergebnis) .then(function(suchergebnis)
{ {

suchergebnis.forEach(element => { suchergebnis.forEach(element => {
if(element.titel==produktname) if(element.titel==produktname)
{ {
this.exists = true;
this.isSelected = element.getStatus().isSelected;
this.ex = true;
this.isSelected = element.getStatus().isSelected;
} }
}); });


{ {
//schreibt den aktuellen Zustand in den store //schreibt den aktuellen Zustand in den store
let suchergebnis = this.get('store').query('produkt', {
filter: {
let suchergebnis = this.store.query('produkt', {
filter:
{
titel: produktname titel: produktname
}});

this.prodn = suchergebnis.titel;


count = suchergebnisse.titel;
this.prodn = element.titel;
suchergebnisse.forEach(element => {
this.prodn = element.titel;
count++;
if(element.titel === produktname)
}}).then(function(element)
{ {
this.prodn = produktname;
element.isSelected = this.isSelected;
this.isSet = !this.isSet;
}
});
element.isSelected = this.isSelected;
});;
} }
} }

+ 0
- 1
app/models/produkt.js View File

@attr einheit; @attr einheit;
@attr bild; @attr bild;



get status() get status()
{ {
return `${this.titel} ${this.IsSelected}` return `${this.titel} ${this.IsSelected}`

+ 3
- 7
app/routes/produkte.js View File

import Route from '@ember/routing/route'; import Route from '@ember/routing/route';
import { inject as service } from '@ember/service'; import { inject as service } from '@ember/service';


const PRODUKT_KATEGORIEN = [
'Pasta',
'Gemüse',
'Milchprodukte',
'Fleisch'
];

export default class ProduktRoute extends Route { export default class ProduktRoute extends Route {


@service store; @service store;
return this.store.findAll('produkt'); return this.store.findAll('produkt');
} }
} }



/*async model() { /*async model() {
let response = await fetch('/api/produkte.json'); let response = await fetch('/api/produkte.json');
let { data } = await response.json(); let { data } = await response.json();

+ 1
- 1
app/templates/rezepte.hbs View File

</Jumbo> </Jumbo>


<Kategorie @titel={{"Pasta"}}> <Kategorie @titel={{"Pasta"}}>
<div class="rentals">
<div class="rezepte">
<ul class="resultsRezept"> <ul class="resultsRezept">
{{#each @model as |rezept|}} {{#each @model as |rezept|}}
{{#if (compare rezept.kategorie '===' 'Pasta')}} {{#if (compare rezept.kategorie '===' 'Pasta')}}

Loading…
Cancel
Save