Exemplo n.º 1
0
  return new Promise((resolve, reject) => {
    const cachedResults = Cache.fetch(LAYOUT_STORAGE_KEY);

    if (typeof cachedResults !== 'undefined') {
      resolve(cachedResults.payload);
    }

    // the profile properties may not exist
    getProfileProperties().then(function(properties) {
      // we have a layout in the user profile, return this...
      const layoutFromProperties = getPropertyData('layout');

      if (layoutFromProperties.length === 0) {
        // no profile properties setup, use the defaults...
        resolve(getDefaultLayout());
      } else if (typeof cachedResults === 'undefined') {
        resolve(layoutFromProperties);
      } else {
        // we have a value, update the cache silently
        Cache.store(LAYOUT_STORAGE_KEY, Utils.buildStoragePayload(layoutFromProperties));
      }
    }).catch(function(reason) {
      if (typeof cachedResults === 'undefined') {
        // first go with standard layout
        resolve(Utils.buildStoragePayload(getDefaultLayout()).payload);
      }
    });
  });
Exemplo n.º 2
0
  return new Promise((resolve, reject) => {
    const settings = Cache.fetch(SETTINGS_STORAGE_KEY);

    if (typeof settings !== 'undefined') {
      resolve(settings.payload);
    }

    getProfileProperties().then(function(properties) {
      const settingsFromProperties = getPropertyData('settings');

      if (settingsFromProperties.length === 0) {
        // no profile properties setup, use the defaults...
        resolve(Utils.buildStoragePayload(getDefaultSettings()).payload);
      } else if (typeof settings === 'undefined') {
        // we have their settings in the user profile, return this...
        resolve(settingsFromProperties);
      } else {
        // we have a value, update the cache silently
        Cache.store(SETTINGS_STORAGE_KEY, Utils.buildStoragePayload(settingsFromProperties));
      }
    }).catch(function(reason) {
      if (typeof settings === 'undefined') {
        // first go with the standard settings
        resolve(Utils.buildStoragePayload(getDefaultSettings()).payload);
      }
    });
  });
Exemplo n.º 3
0
  return new Promise((resolve, reject) => {
    const favourites = Cache.fetch(FAVOURITES_STORAGE_KEY);

    if (typeof favourites !== 'undefined') {
      resolve(favourites.payload);
    }

    getProfileProperties().then(function(properties) {
      const favouritesFromProperties = getPropertyData('favourites');

      if (favouritesFromProperties.length === 0) {
        // no profile properties setup, use the defaults...
        resolve(Utils.buildStoragePayload(getDefaultFavourites()).payload);
      } else if (typeof favourites === 'undefined') {
        // we have their favourites in the user profile, return this...
        resolve(favouritesFromProperties);
      } else {
        // we have a value, update the cache silently
        Cache.store(FAVOURITES_STORAGE_KEY, Utils.buildStoragePayload(favouritesFromProperties));
      }
    }).catch(function(reason) {
      if (typeof favourites === 'undefined') {
        // first go with no favourites
        resolve(Utils.buildStoragePayload(getDefaultFavourites()).payload);
      }
    });
  });
Exemplo n.º 4
0
  return new Promise((resolve, reject) => {
    const cache = Cache.fetch(USERINFO_STORAGE_KEY);

    if (typeof cache !== 'undefined') {
      // we already have them - easy
      resolve(cache.payload);
    } else {
      let collection = [];
      let skip = '';

      if (typeof startId === 'undefined') {
        // reset terms if fetching fresh data
        keys.forEach(function(key) {
          data[key] = data[key] || {
            title: key.split(/(?=[A-Z])/).join(' '),
            terms: [],
            complete: false,
          };
        });
      } else {
        skip = '&p_ID=' + startId;
      }

      const key = !data[keys[0]].complete ? keys[0] : keys[1];
      // we need to process the list 5000 items at a time (we can do that because it's a list).
      const token = encodeURIComponent('Paged=TRUE&p_SortBehavior=0' + skip + '&$top=5000');
      // using the paging token, construct the URL for the REST endpoint
      const url = Utils.getBaseUrl() + '/_api/web/SiteUserInfoList/items?$select=' + key + ',ID&$filter=' + key + '%20ne%20null&$top=5000&$skiptoken=' + token;

      fetchUserInfo(url, key).then(
          function(results) {
            if (typeof results === 'undefined') {
              getBusinessInformation(keys, id);
            } else {
              data[key].complete = true;
            }

            if (Object.keys(data).every(info => data[info].complete)) {
              collection = Object.keys(data).map(function(item) {
                return data[item];
              });

              resolve(collection);

              // save this in the local storage so we don't need to fetch this next time
              Cache.store(USERINFO_STORAGE_KEY, Utils.buildStoragePayload(collection));
            } else if (data[key].complete) {
              // move onto the next one
              getBusinessInformation(keys);
            }
          }
      );
    }
  });