How to use the rx-jupyter.contents.save function in rx-jupyter

To help you get started, we’ve selected a few rx-jupyter examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github nteract / nteract / packages / epics / src / hosts.ts View on Github external
.get(action.payload.contentRef);

      if (!content || content.type !== "notebook") {
        return of({
          type: "ERROR",
          error: true,
          payload: {
            error: new Error("Only Notebooks can be published to Bookstore")
          }
        }) as any;
      }

      const notebook: NotebookV4 = toJS(content.model.notebook);

      // Save notebook first before sending to Bookstore
      return contents
        .save(serverConfig, content.filepath, {
          content: notebook,
          type: "notebook"
        })
        .pipe(
          tap((xhr: AjaxResponse) => {
            if (xhr.status !== 200) {
              throw new Error(xhr.response);
            }
          }),
          map((nb: AjaxResponse) => {
            return actions.publishToBookstoreAfterSave({
              contentRef: action.payload.contentRef,
              model: {
                name: content.filepath.split("/").pop(),
                path: content.filepath,
github nteract / nteract / packages / core / src / epics / contents.js View on Github external
const diskDate = new Date(model.last_modified);
              const inMemoryDate = content.lastSaved
                ? new Date(content.lastSaved)
                : // FIXME: I'm unsure if we don't have a date if we should default to the disk date
                  diskDate;

              if (Math.abs(diskDate - inMemoryDate) > 600) {
                return of(
                  actions.saveFailed({
                    error: new Error("open in another tab possibly..."),
                    contentRef: action.payload.contentRef
                  })
                );
              }

              return contents.save(serverConfig, filepath, saveModel).pipe(
                map(xhr => {
                  return actions.saveFulfilled({
                    contentRef: action.payload.contentRef,
                    model: xhr.response
                  });
                }),
                catchError((error: Error) =>
                  of(
                    actions.saveFailed({
                      error,
                      contentRef: action.payload.contentRef
                    })
                  )
                )
              );
            })
github nteract / nteract / packages / epics / src / contents.ts View on Github external
? new Date(content.lastSaved)
                : // FIXME: I'm unsure if we don't have a date if we should
                  // default to the disk date
                  diskDate;
              const diffDate = diskDate.getTime() - inMemoryDate.getTime();

              if (Math.abs(diffDate) > 600) {
                return of(
                  actions.saveFailed({
                    error: new Error("open in another tab possibly..."),
                    contentRef: action.payload.contentRef
                  })
                );
              }

              return contents.save(serverConfig, filepath, saveModel).pipe(
                mergeMap((saveXhr: AjaxResponse) => {
                  const pollIntervalMs = 500;
                  const maxPollNb = 4;

                  // Last_modified value from jupyter server is unreliable: https://github.com/nteract/nteract/issues/4583
                  // Check last-modified until value is stable.
                  return interval(pollIntervalMs)
                    .pipe(take(maxPollNb))
                    .pipe(
                      mergeMap(x =>
                        contents.get(serverConfig, filepath, { content: 0 }).pipe(
                          map((xhr: AjaxResponse) => {
                            if (xhr.status !== 200 || typeof xhr.response === "string") {
                              return undefined;
                            }
                            const model = xhr.response;
github nteract / nteract / applications / jupyter-extension / nteract_on_jupyter / app / triggers / open-notebook.ts View on Github external
const sessionPayload: SessionPayload = {
          kernel: {
            id: null,
            name: ks.name
          },
          name: "",
          path: filepath,
          type: "notebook"
        };

        return forkJoin(
          // Get their kernel started up
          sessions.create(serverConfig, sessionPayload),
          // Save the initial notebook document
          contents.save(serverConfig, filepath, {
            content: notebook,
            type: "notebook"
          })
        );
      }),
      first(),
github nteract / nteract / packages / epics / src / contents.ts View on Github external
const filepath = action.payload.filepath;

      const { saveModel } = serializeContent(state, content);

      if (!saveModel) {
        return of(
          actions.saveAsFailed({
            error: new Error("No serialized model created for this content."),
            contentRef: action.payload.contentRef
          })
        );
      }

      const serverConfig: ServerConfig = selectors.serverConfig(host);

      return contents.save(serverConfig, filepath, saveModel).pipe(
        map((xhr: AjaxResponse) => {
          return actions.saveAsFulfilled({
            contentRef: action.payload.contentRef,
            model: xhr.response
          });
        }),
        catchError((error: Error) =>
          of(
            actions.saveAsFailed({
              error,
              contentRef: action.payload.contentRef
            })
          )
        )
      );
    })