Skip to content

Add advanced search functionality to object list #7

Description

@pcon

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;
    };
});

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions