<commit_before>// Provides reusable UI methods relating to the publication and management of drafts.

export default {
  methods: {
    // A UI method to publish a document. If errors occur they are displayed to the user
    // appropriately, not returned or thrown to the caller. If a page cannot be published
    // because its ancestors are unpublished, the user is invited to publish its
    // ancestors first, and the publish operation is then retried.
    //
    // A notification of success is displayed, with a button to revert the published
    // mode of the document to its previous value.
    //
    // Returns `true` if the document was ultimately published.
    async publish(doc) {
      const previouslyPublished = !!doc.lastPublishedAt;
      const action = window.apos.modules[doc.type].action;
      try {
        await apos.http.post(`${action}/${doc._id}/publish`, {
          body: {},
          busy: true
        });
        const event = {
          name: previouslyPublished ? 'revert-published-to-previous' : 'unpublish',
          data: {
            action,
            _id: doc._id
          }
        };
        apos.notify(`Your changes have been published. <button data-apos-bus-event='${JSON.stringify(event)}'>Undo Publish</button>`, {
          type: 'success',
          dismiss: true
        });
        return true;
      } catch (e) {
        if ((e.name === 'invalid') && e.body && e.body.data && e.body.data.unpublishedAncestors) {
          if (await apos.confirm({
            heading: 'One or more parent pages have not been published',
            description: `To publish this page, you must also publish the following pages: ${e.body.data.unpublishedAncestors.map(page => page.title).join(', ')}.\nDo you want to do that now?`
          })) {
            try {
              for (const page of e.body.data.unpublishedAncestors) {
                await apos.http.post(`${action}/${page._id}/publish`, {
                  body: {},
                  busy: true
                });
              }
              // Retry now that ancestors are published
              return this.publish(action, _id, previouslyPublished);
            } catch (e) {
              await apos.alert({
                heading: 'An Error Occurred While Publishing',
                description: e.message || 'An error occurred while publishing a parent page.'
              });
            }
          }
        } else {
          await apos.alert({
            heading: 'An Error Occurred While Publishing',
            description: e.message || 'An error occurred while publishing the document.'
          });
        }
        return false;
      }<commit_msg>eslint caught this one<commit_after>// Provides reusable UI methods relating to the publication and management of drafts.

export default {
  methods: {
    // A UI method to publish a document. If errors occur they are displayed to the user
    // appropriately, not returned or thrown to the caller. If a page cannot be published
    // because its ancestors are unpublished, the user is invited to publish its
    // ancestors first, and the publish operation is then retried.
    //
    // A notification of success is displayed, with a button to revert the published
    // mode of the document to its previous value.
    //
    // Returns `true` if the document was ultimately published.
    async publish(doc) {
      const previouslyPublished = !!doc.lastPublishedAt;
      const action = window.apos.modules[doc.type].action;
      try {
        await apos.http.post(`${action}/${doc._id}/publish`, {
          body: {},
          busy: true
        });
        const event = {
          name: previouslyPublished ? 'revert-published-to-previous' : 'unpublish',
          data: {
            action,
            _id: doc._id
          }
        };
        apos.notify(`Your changes have been published. <button data-apos-bus-event='${JSON.stringify(event)}'>Undo Publish</button>`, {
          type: 'success',
          dismiss: true
        });
        return true;
      } catch (e) {
        if ((e.name === 'invalid') && e.body && e.body.data && e.body.data.unpublishedAncestors) {
          if (await apos.confirm({
            heading: 'One or more parent pages have not been published',
            description: `To publish this page, you must also publish the following pages: ${e.body.data.unpublishedAncestors.map(page => page.title).join(', ')}.\nDo you want to do that now?`
          })) {
            try {
              for (const page of e.body.data.unpublishedAncestors) {
                await apos.http.post(`${action}/${page._id}/publish`, {
                  body: {},
                  busy: true
                });
              }
              // Retry now that ancestors are published
              return this.publish(action, doc._id, previouslyPublished);
            } catch (e) {
              await apos.alert({
                heading: 'An Error Occurred While Publishing',
                description: e.message || 'An error occurred while publishing a parent page.'
              });
            }
          }
        } else {
          await apos.alert({
            heading: 'An Error Occurred While Publishing',
            description: e.message || 'An error occurred while publishing the document.'
          });
        }
        return false;
      }
{'fraction_non_alphanumeric': 0.1052143254778252, 'fraction_numerical': 0.0, 'mean_word_length': 1.8443271767810026, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3870228', 'n_tokens_mistral': 1374, 'n_tokens_neox': 1356, 'n_words': 479}