<commit_before>/**
 * Created by ksinger on 08.10.2015.
 */

import won from './won-es6';
import Immutable from 'immutable';
import { actionTypes, actionCreators } from './actions/actions';
import {
    accountLogin,
    accountLogout,
} from './actions/account-actions';

import {
    checkLoginStatus,
    privateId2Credentials,
} from './won-utils';

import {
    selectAllNeeds,
} from './selectors';

import {
    decodeUriComponentProperly,
    checkHttpStatus,
    getIn,
} from './utils';


/**
 * As we have configured our router to keep parameters unchanged,
 * that aren't mentioned in the `stateGo`-calls, you can use this
 * array to reset them explicitly (or merge anything else on top,
 * by using the `makeParams`-function).
 *
 * NOTE: WHEN INTRODUCING NEW PARAMETERS, ADD THEM HERE
 * AS WELL.
 */
export const resetParams = Object.freeze({
    connectionType: undefined,
    connectionUri: undefined,
    layout: undefined,
    myUri: undefined,
    postUri: undefined,
    // privateId: undefined,  // global parameter that we don't want to lose. never reset this one.
});

export const resetParamsImm = Immutable.fromJS(resetParams);

/**
 * These should not accidentally be removed from the state. See the `stateGo*`-action creators
 * in `actions.js`
 * @type {string[]}
 */
export const constantParams = [
    'privateId',
];


/**
 * Adapted from https://github.com/neilff/redux-ui-router/blob/master/example/index.js
 * @param $urlRouterProvider
 * @param $stateProvider
 */
export const configRouting = [ '$urlRouterProvider', '$stateProvider', ($urlRouterProvider, $stateProvider) => {
    //$urlRouterProvider.otherwise('/landingpage');
    $urlRouterProvider.otherwise(($injector, $location) => {
        console.log('otherwise ', $injector, $location)

        //let updatedRoute =  $location.replace()
        //    .path('/landingpage') // change route to landingpage
        $location.path('/landingpage') // change route to landingpage

        const origParams = $location.search();
        if(origParams) {
            const onlyConstParams = addConstParams({}, origParams);
            //updatedRoute.search(onlyConstParams); // strip all but "constant" parameters
            $location.search(onlyConstParams);
        }

        //return updatedRoute;
    });

    //make sure create-need is called with a draftId
    //$urlRouterProvider.when('/create-need/', [() => '/create-need/' + getRandomPosInt()]);

    [
        { path: '/about?privateId', component: 'about' },
        { path: '/signup?privateId', component: 'signup' },
        { path: '/landingpage?privateId', component: 'landingpage' },
        { path: '/create-need/?privateId', component: 'create-need' },
        { path: '/feed?privateId', component: 'feed' },
        { path: '/overview/matches?privateId?layout?myUri?connectionUri', component: 'overview-matches', as: 'overviewMatches' },
        { path: '/overview/incoming-requests?privateId?myUri?connectionUri', component: 'overview-incoming-requests', as: 'overviewIncomingRequests' },
        { path: '/overview/sent-requests?privateId?myUri?connectionUri', component: 'overview-sent-requests', as: 'overviewSentRequests' },
        { path: '/overview/posts?privateId', component: 'overview-posts', as: 'overviewPosts' },
        { path: '/post/?privateId?postUri?connectionUri?connectionType?layout', component: 'post', as: 'post' },

    ].forEach( ({path, component, as}) => {

            const cmlComponent = hyphen2Camel(component);

            if(!path) path = `/${component}`;
            if(!as) as = firstToLowerCase(cmlComponent);

            $stateProvider.state(as, {
                url: path,
                templateUrl: `./app/components/${component}/${component}.html`,
                // template: `<${component}></${component>` TODO use directives instead of view+ctrl
                controller: `${cmlComponent}Controller`,
                controllerAs: 'self',
                scope: {}
            });
        })

    $urlRouterProvider.when('/settings/', '/settings/general');

    $stateProvider
        .state('settings', {
            url: '/settings',
            templateUrl: './app/components/settings/settings.html'<commit_msg>adds sendAdHocRequest parameter for "direct" conversation requests without a prior existing need2need connection<commit_after>/**
 * Created by ksinger on 08.10.2015.
 */

import won from './won-es6';
import Immutable from 'immutable';
import { actionTypes, actionCreators } from './actions/actions';
import {
    accountLogin,
    accountLogout,
} from './actions/account-actions';

import {
    checkLoginStatus,
    privateId2Credentials,
} from './won-utils';

import {
    selectAllNeeds,
} from './selectors';

import {
    decodeUriComponentProperly,
    checkHttpStatus,
    getIn,
} from './utils';


/**
 * As we have configured our router to keep parameters unchanged,
 * that aren't mentioned in the `stateGo`-calls, you can use this
 * array to reset them explicitly (or merge anything else on top,
 * by using the `makeParams`-function).
 *
 * NOTE: WHEN INTRODUCING NEW PARAMETERS, ADD THEM HERE
 * AS WELL.
 */
export const resetParams = Object.freeze({
    connectionType: undefined,
    connectionUri: undefined,
    layout: undefined,
    myUri: undefined,
    postUri: undefined,
    sendAdHocRequest: undefined,
    // privateId: undefined,  // global parameter that we don't want to lose. never reset this one.
});

export const resetParamsImm = Immutable.fromJS(resetParams);

/**
 * These should not accidentally be removed from the state. See the `stateGo*`-action creators
 * in `actions.js`
 * @type {string[]}
 */
export const constantParams = [
    'privateId',
];


/**
 * Adapted from https://github.com/neilff/redux-ui-router/blob/master/example/index.js
 * @param $urlRouterProvider
 * @param $stateProvider
 */
export const configRouting = [ '$urlRouterProvider', '$stateProvider', ($urlRouterProvider, $stateProvider) => {
    //$urlRouterProvider.otherwise('/landingpage');
    $urlRouterProvider.otherwise(($injector, $location) => {
        console.log('otherwise ', $injector, $location)

        //let updatedRoute =  $location.replace()
        //    .path('/landingpage') // change route to landingpage
        $location.path('/landingpage') // change route to landingpage

        const origParams = $location.search();
        if(origParams) {
            const onlyConstParams = addConstParams({}, origParams);
            //updatedRoute.search(onlyConstParams); // strip all but "constant" parameters
            $location.search(onlyConstParams);
        }

        //return updatedRoute;
    });

    //make sure create-need is called with a draftId
    //$urlRouterProvider.when('/create-need/', [() => '/create-need/' + getRandomPosInt()]);

    [
        { path: '/about?privateId', component: 'about' },
        { path: '/signup?privateId', component: 'signup' },
        { path: '/landingpage?privateId', component: 'landingpage' },
        { path: '/create-need/?privateId', component: 'create-need' },
        { path: '/feed?privateId', component: 'feed' },
        { path: '/overview/matches?privateId?layout?myUri?connectionUri?sendAdHocRequest', component: 'overview-matches', as: 'overviewMatches' },
        { path: '/overview/incoming-requests?privateId?myUri?connectionUri', component: 'overview-incoming-requests', as: 'overviewIncomingRequests' },
        { path: '/overview/sent-requests?privateId?myUri?connectionUri', component: 'overview-sent-requests', as: 'overviewSentRequests' },
        { path: '/overview/posts?privateId', component: 'overview-posts', as: 'overviewPosts' },
        { path: '/post/?privateId?postUri?connectionUri?connectionType?layout?sendAdHocRequest', component: 'post', as: 'post' },

    ].forEach( ({path, component, as}) => {

            const cmlComponent = hyphen2Camel(component);

            if(!path) path = `/${component}`;
            if(!as) as = firstToLowerCase(cmlComponent);

            $stateProvider.state(as, {
                url: path,
                templateUrl: `./app/components/${component}/${component}.html`,
                // template: `<${component}></${component>` TODO use directives instead of view+ctrl
                controller: `${cmlComponent}Controller`,
                controllerAs: 'self',
                scope: {}
            });
        })

    $urlRouterProvider.when('/settings/', '/settings/general');

    $stateProvider
        .state('settings', {
            url: '/settings',
            templateUrl: './app/components/settings/settings.html'
{'fraction_non_alphanumeric': 0.14408352668213456, 'fraction_numerical': 0.0026682134570765663, 'mean_word_length': 3.111111111111111, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 15, 'https://': 2, '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': '1564457', 'n_tokens_mistral': 2472, 'n_tokens_neox': 2387, 'n_words': 587}