Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add advanced search functionality to object list #7

Open
pcon opened this issue Oct 13, 2017 · 0 comments
Open

Add advanced search functionality to object list #7

pcon opened this issue Oct 13, 2017 · 0 comments
Assignees

Comments

@pcon
Copy link
Owner

pcon commented Oct 13, 2017

Need to covert the code below to SLDS styling and add it to the objDesc app's sidebar search

<div>
    <a style="margin-right: 5px; width: 100%;" class="pull-right text-right" onclick="toggleAdvancedSearch()" data-toggle="collapse" aria-expanded="false" aria-controls="advancedSearch">Advanced...</a>
</div>
<div class="clearfix"></div>
<div class="collapse" id="advancedSearch">
    <div style="width: 100%;" class="form-group">
        <label for="namespace" class="text-muted" style="font-weight: normal;">Namespace</label>
        <select class="pull-right form-control" id="namespace" ng-model="namespace">
            <option value="all" selected>All</option>
            <option value="none">None</option>
            <option ng-repeat="namespace in namespaces" value="{{ namespace }}">{{ namespace }}</option>
        </select>
    </div>
    <div style="width: 100%;" class="form-group">
        <label class="text-muted" style="width: 100%; font-weight: normal;">Include Tags <input type="checkbox" class="pull-right" ng-model="includeTags"></label>
    </div>
    <div style="width: 100%;" class="form-group">
        <label class="text-muted" style="width: 100%; font-weight: normal;">Include History <input type="checkbox" class="pull-right" ng-model="includeHistory"></label>
    </div>
    <div style="width: 100%;" class="form-group">
        <label class="text-muted" style="width: 100%; font-weight: normal;">Include Shares <input type="checkbox" class="pull-right" ng-model="includeShares"></label>
    </div>
</div>

Also an update to the query

<li ng-repeat="object in objects | filterNamespace:namespace | removeTags:includeTags | removeShares:includeShares | removeHistory:includeHistory | filter:query">

Will also require the following to the controller

function getNamespace(name) {
    'use strict';
    var name_parts = name.replace(/__c$/, '').replace(/__Tag$/, '').replace(/__History$/).replace(/__Share$/).split('__');
    if (name_parts.length === 2) {
        return name_parts[0];
    }
    return undefined;
}

//CUT
$scope.namespaces = [];
_.forEach($scope.objects, function (object) {
    var namespace = getNamespace(object.name);
    if (namespace) {
        $scope.namespaces.push(namespace);
    }
});
$scope.namespaces = _.sortedUniq($scope.namespaces);
$scope.namespace = 'all';

//CUT
angular.module('ccmApp').filter('removeTags', function () {
    'use strict';
    return function (objects, includeTags) {
        if (includeTags) {
            return objects;
        }
        return filterName(objects, '__tag');
    };
});
angular.module('ccmApp').filter('removeShares', function () {
    'use strict';
    return function (objects, includeShares) {
        if (includeShares) {
            return objects;
        }
        return filterName(objects, '__share');
    };
});
angular.module('ccmApp').filter('removeHistory', function () {
    'use strict';
    return function (objects, includeHistory) {
        if (includeHistory) {
            return objects;
        }
        return filterName(objects, '__history');
    };
});

angular.module('ccmApp').filter('filterNamespace', function () {
    'use strict';
    return function (objects, namespace) {
        if (!namespace || namespace === 'all') {
            return objects;
        }
        var results = [];
        _.forEach(objects, function (object) {
            if (namespace === 'none') {
                if (getNamespace(object.name) === undefined) {
                    results.push(object);
                }
            } else if (_.startsWith(object.name.toLowerCase(), namespace.toLowerCase() + '__')) {
                results.push(object);
            }
        });
        return results;
    };
});
@pcon pcon self-assigned this Oct 13, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant