osdir.com


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[GitHub] brooklyn-ui pull request #94: Composer recent and filters


Github user ahgittin commented on a diff in the pull request:

    https://github.com/apache/brooklyn-ui/pull/94#discussion_r229309854
  
    --- Diff: ui-modules/blueprint-composer/app/components/providers/recently-used-service.provider.js ---
    @@ -0,0 +1,62 @@
    +/*
    + * Licensed to the Apache Software Foundation (ASF) under one
    + * or more contributor license agreements.  See the NOTICE file
    + * distributed with this work for additional information
    + * regarding copyright ownership.  The ASF licenses this file
    + * to you under the Apache License, Version 2.0 (the
    + * "License"); you may not use this file except in compliance
    + * with the License.  You may obtain a copy of the License at
    + *
    + *     http://www.apache.org/licenses/LICENSE-2.0
    + *
    + * Unless required by applicable law or agreed to in writing,
    + * software distributed under the License is distributed on an
    + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
    + * KIND, either express or implied.  See the License for the
    + * specific language governing permissions and limitations
    + * under the License.
    + */
    +
    +export function recentlyUsedServiceProvider() {
    +    return {
    +        $get: ['$log', function ($log) { return new RecentlyUsedService($log); }]
    +    }
    +}
    +
    +export const PREFIX = 'org.apache.brooklyn.composer.lastUsed:';
    +
    +function RecentlyUsedService($log) {
    +    let service = {};
    +    
    +    service.getId = (brooklynObject) => {
    +        if (typeof brooklynObject === 'string') return brooklynObject;
    +        return (brooklynObject.containingBundle || '?') + "::" + 
    +            (brooklynObject.symbolicName || '?') + ":" + (brooklynObject.version || '?');
    +    };
    +    
    +    service.markUsed = (item, when) => {
    +        let id = service.getId(item);
    +        if (when) {
    +            let old = service.getLastUsed(id);
    +            if (old > when) return;
    +        } else {
    +            when = Date.now();
    +        }
    +        sessionStorage.setItem(PREFIX+id, when);
    --- End diff --
    
    seems like the issue is that it can through; will handle that with `try ... catch`, good point.  won't convert to stringified map unless you know a good reason to do that.


---