<commit_before>/**
 * Created by Shin on 24/09/2016.
 */
import { computed, observable, autorun } from 'mobx';
import WorkshopModel from '../models/WorkshopModel';
import { searchWorkshops } from '../api/workshop.api';

class WorkshopsStore {
    @observable workshops = [];
    @observable single = null;

    //TODO: Complete this when Workshop API is working
    fetchWorkshops(studentId, workshopSetId) {
        searchWorkshops({

            workshopSetId: workshopSetId
        }).then((response) => {

            console.log('Workshop data fetched');
            console.log(response.data.Results);

            this.workshops = response.data.Results.map((data) => {
                return this.mapDataToModel(data);
            });
        }).catch((error) => {
            console.log(error);
        })
    }

    //Ability to fetch from local data if local data exist
    findWorkshopById(workshopId) {
        searchWorkshops({
            workshopId: workshopId
        }).then((response) => {
            this.single = this.mapDataToModel(
                response.data.Results.find((workshop) => {
                    return workshop.WorkshopId == workshopId;
                })
            );

        }).catch((error) => {
            console.log(error);<commit_msg>SearchById fixed by using page trick<commit_after>/**
 * Created by Shin on 24/09/2016.
 */
import { computed, observable, autorun } from 'mobx';
import WorkshopModel from '../models/WorkshopModel';
import { searchWorkshops } from '../api/workshop.api';

class WorkshopsStore {
    @observable workshops = [];
    @observable single = null;

    //TODO: Complete this when Workshop API is working
    fetchWorkshops(studentId, workshopSetId) {
        searchWorkshops({

            workshopSetId: workshopSetId
        }).then((response) => {

            console.log('Workshop data fetched');
            console.log(response.data.Results);

            this.workshops = response.data.Results.map((data) => {
                return this.mapDataToModel(data);
            });
        }).catch((error) => {
            console.log(error);
        })
    }

    //Ability to fetch from local data if local data exist
    findWorkshopById(workshopId) {

        //API does not know how to use workshopId to search.
        //Use page and pageSize trick to search.
        //Plussing 1 because page starts from 1
        //Default number of items queries is 10
        let pageVal = Math.floor(workshopId / 10) + 1;
        searchWorkshops({
            page: pageVal
        }).then((response) => {
            this.single = this.mapDataToModel(
                response.data.Results.find((workshop) => {
                    return workshop.WorkshopId == workshopId;
                })
            );

        }).catch((error) => {
            console.log(error);
{'fraction_non_alphanumeric': 0.1191145467322558, 'fraction_numerical': 0.008081517919887562, 'mean_word_length': 2.0031645569620253, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7130661', 'n_tokens_mistral': 788, 'n_tokens_neox': 742, 'n_words': 188}