LiskArchive / lisk-explorer

📦 Lisk blockchain explorer
https://explorer.lisk.io/
GNU General Public License v3.0
121 stars 65 forks source link

Possibility to set breadcrumbs from async function in controller #141

Closed 4miners closed 7 years ago

4miners commented 7 years ago

Current behavior: It's not possible to set breadcrumbs from async function in controller.

Expected behavior: Should be possible to update breadcrumbs (current and parents) from async function in controller, for example:

        $http.get('...', {
            params: {
                something: $stateParams.something
            }
        }).then(function (resp) {
            if (resp.data.success) {
                               //HERE
            } else {
                throw 'Account was not found!';
            }
        }).catch(function (error) {
            $location.path('/');
        });

Steps to reproduce: Change controllers/delegates.js to:

'use strict';

var DelegateCtrlConstructor = function ($rootScope, $stateParams, $location, $http, addressTxs) {
    var vm = this;

    vm.getAddress = function () {
        $http.get('/api/getAccount', {
            params: {
                address: $stateParams.delegateId
            }
        }).then(function (resp) {
            if (resp.data.success) {
                vm.address = resp.data;
                $rootScope.breadCrumb = {address: $stateParams.delegateId};  //HERE
            } else {
                throw 'Account was not found!';
            }
        }).catch(function (error) {
            $location.path('/');
        });
    };

    vm.address = {
        address: $stateParams.delegateId
    };

    // Sets the filter for which transactions to display
    vm.filterTxs = function(direction) {
        vm.direction = direction;
        vm.txs = addressTxs($stateParams.delegateId, direction);
    };

    vm.getAddress();
    vm.txs = addressTxs($stateParams.delegateId);
};

angular.module('lisk_explorer.address').controller('DelegateCtrl', DelegateCtrlConstructor);
4miners commented 7 years ago

There is library https://github.com/ncuillery/angular-breadcrumb which is good, easy for use and doesn't have issues https://github.com/LiskHQ/lisk-explorer/issues/121 https://github.com/LiskHQ/lisk-explorer/issues/127, but unfortunately doesn't support feature described here - so using custom solution probably is still the way to go.

reyraa commented 7 years ago

I don't understand the situation, if you're updating the breadcrumb using $stateParams why do you need to do it in an async function?

4miners commented 7 years ago

@alihaghighatkhah Updating using data from $stateParams was just example, I want to update using data retriewed from async function. For example - I have page /delegate/<delegate_name> but need breadcrumbs Home / Address / Delegate. So I need to get address via async function and set breadcrumbs.