Home Reference Source

application/managers/assignment-manager/index.js

import Immutable from 'immutable';
import {browserHistory} from 'react-router';

import {
    assignmentsFetch
} from '../../redux/actions/assignment-actions';

import request from './../../util/request';

export default {

    get: function(uuid) {

    },

    fetch: function(props = {}) {
        const myProps = Object.assign({}, {
            'per_page': 40,
            'page': 1
        }, props);

        return window.Store.dispatch(assignmentsFetch(props));
    },

    fetchFromView: function() {
        const props = this.translateProps(window.Store.getState().assignmentView);
        browserHistory.push(request.getPath() + '?' + request.setQuery(props));

        localStorage.setItem("assignmentCalendarView", props.calView);
        localStorage.setItem("assignmentPageView", props.cal);
        return window.Store.dispatch(assignmentsFetch(props));
    },

    translateProps: function(props) {
        return {
            page: props.page ? props.page : 1,
            type: props.type ? props.type : 'unscheduled',
            keywords: props.keywords ? props.keywords : null,
            workflow: props.workflow ? props.workflow : null,
            status: props.status ? props.status : null,
            order: props.sorter  ? props.sorter : 'due_at',
            dir: props.flip ? 'asc' : 'desc',
            hpd: props.hpd ? props.hpd :  false,
            cal: props.cal ? props.cal : false,
            calview: props.calview ? props.calview : 'issue',
            assignee: props.assignee ? props.assignee : null,
            issues: props.issues ? props.issues : null,
            start: props.start ? props.start : null,
            end: props.end ? props.end : null
        };
    },

    propsFromUrl() {
        const query = request.getQuery(false);

        let cal = query.cal ? query.cal : false;
        if (localStorage.getItem('assignmentPageView')) {
            cal = localStorage.getItem('assignmentPageView');
        }

        let calView = query.calview ? query.calview : 'issue';
        if (localStorage.getItem("assignmentCalendarView")) {
            calView = localStorage.getItem("assignmentCalendarView");
        }

        return {
            page: query.page ? query.page : 1,
            type: query.type ? query.type : 'unscheduled',
            keywords: query.keywords ? query.keywords : null,
            workflow: query.workflow ? query.workflow : null,
            status: query.status ? query.status : null,
            sorter: query.order  ? query.order : 'due_at',
            flip: query.dir == 'asc' ? true : false,
            hpd: query.hpd ? query.hpd :  false,
            cal: cal,
            calview: calView,
            assignee: query.assignee ? query.assignee : null,
            issues: query.issues ? query.issues : null,
            start: query.start ? query.start : null,
            end: query.end ? query.end : null
        };
    }
};