{"size": 2161, "ext": "js", "max_stars_repo_path": "app/resources/js/mixins/RouteMixin.js", "max_stars_repo_name": "FoxMalder/photo-blog", "max_stars_repo_stars_event_min_datetime": "2016-12-06T17:49:01.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-19T20:28:02.000Z", "max_issues_repo_path": "app/resources/js/mixins/RouteMixin.js", "max_issues_repo_name": "ehusby/photo-blog", "max_issues_repo_issues_event_min_datetime": "2018-05-12T22:04:33.000Z", "max_issues_repo_issues_event_max_datetime": "2020-07-07T19:11:00.000Z", "max_forks_repo_path": "app/resources/js/mixins/RouteMixin.js", "max_forks_repo_name": "ehusby/photo-blog", "max_forks_repo_forks_event_min_datetime": "2016-12-08T00:09:36.000Z", "max_forks_repo_forks_event_max_datetime": "2021-07-15T19:09:55.000Z"}
{"max_stars_count": 66, "max_issues_count": 5, "max_forks_count": 24, "avg_line_length": 32.7424242424, "max_line_length": 98, "alphanum_fraction": 0.4909763998}
import _, {includes, isUndefined, negate} from "lodash";
import {routeName} from "../router/identifiers";

export default {
    methods: {
        goToPath(path = null) {
            if (path !== null) {
                this.$router.push({path});
                return;
            }

            // If no path was provided go to the home page by default.
            this.goToHomePage();
        },
        goToRedirectUrl() {
            this.goToPath(this.$route.query.redirectUrl);
        },
        goToBackUrl() {
            this.goToPath(this.$route.query.backUrl);
        },
        goToHomePage() {
            this.$router.push({name: routeName.home});
        },
        goToNotFoundPage() {
            this.$router.push({name: routeName.route404});
        },
        goToSignInPage() {
            this.$router.push({name: routeName.signIn});
        },
        goToPhotoPage(id, args = {...this.$route.params, ...this.$route.query}) {
            let name, params = {}, query = {};

            name = routeName.photo;
            params.id = id;

            // Omit junk query parameters.
            query = _(args)
                .pickBy(negate(isUndefined))
                .pickBy((value, key) => includes(["searchPhrase", "tag", "page", "backUrl"], key))
                .value();

            this.$router.replace({name, params, query});
        },
        goToPhotosPage(args = {...this.$route.params, ...this.$route.query}) {
            let name, params = {};

            // Omit junk route parameters.
            params = _(args)
                .pickBy(negate(isUndefined))
                .pickBy((value, key) => includes(["searchPhrase", "tag", "page"], key))
                .value();

            // Choose the right route name based on available route parameters.
            if (typeof params.searchPhrase !== "undefined") {
                name = routeName.photosSearch;
            } else if (typeof params.tag !== "undefined") {
                name = routeName.photosTag;
            } else {
                name = routeName.photos;
            }

            this.$router.push({name, params});
        },
    },
}
