Esempio n. 1
0
            updateUrl: (card, isDirty=false, replaceState=false) => {
                if (!card) {
                    return;
                }
                var copy = cleanCopyCard(card);
                var newState = {
                    card: copy,
                    cardId: copy.id,
                    serializedCard: serializeCardForUrl(copy)
                };

                if (angular.equals(window.history.state, newState)) {
                    return;
                }

                var url = urlForCardState(newState, isDirty);

                // if the serialized card is identical replace the previous state instead of adding a new one
                // e.x. when saving a new card we want to replace the state and URL with one with the new card ID
                replaceState = replaceState || (window.history.state && window.history.state.serializedCard === newState.serializedCard);

                // ensure the digest cycle is run, otherwise pending location changes will prevent navigation away from query builder on the first click
                $scope.$apply(() => {
                    // prevents infinite digest loop
                    // https://stackoverflow.com/questions/22914228/successfully-call-history-pushstate-from-angular-without-inifinite-digest
                    $location.url(url);
                    $location.replace();
                    if (replaceState) {
                        window.history.replaceState(newState, null, $location.absUrl());
                    } else {
                        window.history.pushState(newState, null, $location.absUrl());
                    }
                });
            }
Esempio n. 2
0
export function question(cardId, hash = "", query = "") {
  if (hash && typeof hash === "object") {
    hash = serializeCardForUrl(hash);
  }
  if (query && typeof query === "object") {
    query = Object.entries(query)
      .map(kv => {
        if (Array.isArray(kv[1])) {
          return kv[1]
            .map(v => `${encodeURIComponent(kv[0])}=${encodeURIComponent(v)}`)
            .join("&");
        } else {
          return kv.map(encodeURIComponent).join("=");
        }
      })
      .join("&");
  }
  if (hash && hash.charAt(0) !== "#") {
    hash = "#" + hash;
  }
  if (query && query.charAt(0) !== "?") {
    query = "?" + query;
  }
  // NOTE that this is for an ephemeral card link, not an editable card
  return cardId != null
    ? `/question/${cardId}${query}${hash}`
    : `/question${query}${hash}`;
}
Esempio n. 3
0
        function loadSerializedCard(serialized) {
            const card = deserializeCardFromUrl(serialized);

            if (serialized !== serializeCardForUrl(startNewCard(card.dataset_query.type))) {
                card.isDirty = true;
            }

            return card;
        }
Esempio n. 4
0
  ) => (dispatch, getState) => {
    if (!card) {
      return;
    }
    let copy = cleanCopyCard(card);
    let newState = {
      card: copy,
      cardId: copy.id,
      serializedCard: serializeCardForUrl(copy),
    };

    const { currentState } = getState().qb;

    if (Utils.equals(currentState, newState)) {
      return;
    }

    let url = urlForCardState(newState, dirty);

    // if the serialized card is identical replace the previous state instead of adding a new one
    // e.x. when saving a new card we want to replace the state and URL with one with the new card ID
    replaceState =
      replaceState ||
      (currentState && currentState.serializedCard === newState.serializedCard);

    const urlParsed = urlParse(url);
    const locationDescriptor = {
      pathname: urlParsed.pathname,
      search: preserveParameters ? window.location.search : "",
      hash: urlParsed.hash,
      state: newState,
    };

    if (
      locationDescriptor.pathname === window.location.pathname &&
      (locationDescriptor.search || "") === (window.location.search || "") &&
      (locationDescriptor.hash || "") === (window.location.hash || "")
    ) {
      replaceState = true;
    }

    // this is necessary because we can't get the state from history.state
    dispatch(setCurrentState(newState));
    if (replaceState) {
      dispatch(replace(locationDescriptor));
    } else {
      dispatch(push(locationDescriptor));
    }
  },
Esempio n. 5
0
 function resetDirty() {
     savedCardSerialized = serializeCardForUrl(card);
 }
Esempio n. 6
0
        function cardIsDirty() {
            var newCardSerialized = serializeCardForUrl(card);

            return newCardSerialized !== savedCardSerialized;
        }
Esempio n. 7
0
File: utils.js Progetto: aq/metabase
export const getQuestionUrl = getQuestionArgs => `/q#${serializeCardForUrl(getQuestion(getQuestionArgs))}`;