<commit_before>import { AppController } from './controllers';
import { DefaultAdminAccessRoles } from '/imports/config/permissions';
import Surveys from '/imports/api/surveys/surveys';
import Questions from '/imports/api/questions/questions';
import '/imports/ui/surveys/surveysListView';
import '/imports/ui/surveys/surveyForm';
import '/imports/ui/surveys/surveyFormBuilder';
import '/imports/ui/responses/responsesNew';


Router.route('adminDashboardsurveysView', {
  path: '/surveys',
  template: Template.surveysListView,
  controller: AppController,
  authorize: {
    allow() {
      return Roles.userIsInRole(Meteor.userId(), DefaultAdminAccessRoles);
    },
  },
  waitOn() {
    return Meteor.subscribe('surveys.all');
  },
  data() {
    return {
      title: 'Surveys',
      subtitle: 'List',
    };
  },
});


Router.route('surveysNew', {
  path: '/surveys/new',
  template: Template.surveyForm,
  controller: AppController,
  waitOn() {
    return Meteor.subscribe('questions.all');
  },
  data() {
    const definition = {
      variables: {},
      items: [],
    };
    return {
      title: 'Surveys',
      subtitle: 'New',
      survey: {
        definition: JSON.stringify(definition),
      },
      questions: Questions.find().fetch(),
    };
  },
});

Router.route('surveysEdit', {
  path: '/surveys/:_id/edit',
  template: Template.surveyForm,
  controller: AppController,
  authorize: {
    allow() {
      return Roles.userIsInRole(Meteor.userId(), DefaultAdminAccessRoles);
    },
  },
  waitOn() {
    const id = Router.current().params._id;
    return [
      Meteor.subscribe('surveys.one', id),
      Meteor.subscribe('questions.all'),
    ];
  },
  data() {
    const id = Router.current().params._id;
    const survey = Surveys.findOne(id) || {};
    return {
      title: 'Surveys',
      subtitle: survey ? `Edit ${survey.title}` : '',
      survey,
      questions: Questions.find().fetch(),
    };
  },
});

Router.route('surveysEditDefinition', {
  path: '/surveys/:_id/builder',
  template: Template.surveyFormBuilder,
  controller: AppController,
  authorize: {
    allow() {
      return Roles.userIsInRole(Meteor.userId(), DefaultAdminAccessRoles);
    },
  },
  waitOn() {
    const id = Router.current().params._id;
    return [
      Meteor.subscribe('surveys.one', id),<commit_msg>optimize subscriptions on survey edit<commit_after>import { AppController } from './controllers';
import { DefaultAdminAccessRoles } from '/imports/config/permissions';
import Surveys from '/imports/api/surveys/surveys';
import Questions from '/imports/api/questions/questions';
import '/imports/ui/surveys/surveysListView';
import '/imports/ui/surveys/surveyForm';
import '/imports/ui/surveys/surveyFormBuilder';
import '/imports/ui/responses/responsesNew';


Router.route('adminDashboardsurveysView', {
  path: '/surveys',
  template: Template.surveysListView,
  controller: AppController,
  authorize: {
    allow() {
      return Roles.userIsInRole(Meteor.userId(), DefaultAdminAccessRoles);
    },
  },
  waitOn() {
    return Meteor.subscribe('surveys.all');
  },
  data() {
    return {
      title: 'Surveys',
      subtitle: 'List',
    };
  },
});


Router.route('surveysNew', {
  path: '/surveys/new',
  template: Template.surveyForm,
  controller: AppController,
  // waitOn() {
  //   return Meteor.subscribe('questions.all');
  // },
  data() {
    const definition = {
      variables: {},
      items: [],
    };
    return {
      title: 'Surveys',
      subtitle: 'New',
      survey: {
        definition: JSON.stringify(definition),
      },
      questions: Questions.find().fetch(),
    };
  },
});

Router.route('surveysEdit', {
  path: '/surveys/:_id/edit',
  template: Template.surveyForm,
  controller: AppController,
  authorize: {
    allow() {
      return Roles.userIsInRole(Meteor.userId(), DefaultAdminAccessRoles);
    },
  },
  waitOn() {
    const id = Router.current().params._id;
    return [
      Meteor.subscribe('surveys.one', id),
      // <Meteor.subscribe('questions.all'),
    ];
  },
  data() {
    const id = Router.current().params._id;
    const survey = Surveys.findOne(id) || {};
    return {
      title: 'Surveys',
      subtitle: survey ? `Edit ${survey.title}` : '',
      survey,
      questions: Questions.find().fetch(),
    };
  },
});

Router.route('surveysEditDefinition', {
  path: '/surveys/:_id/builder',
  template: Template.surveyFormBuilder,
  controller: AppController,
  authorize: {
    allow() {
      return Roles.userIsInRole(Meteor.userId(), DefaultAdminAccessRoles);
    },
  },
  waitOn() {
    const id = Router.current().params._id;
    return [
      Meteor.subscribe('surveys.one', id),
{'fraction_non_alphanumeric': 0.1612353567625133, 'fraction_numerical': 0.0, 'mean_word_length': 3.234445446348061, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 3, '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': '4139458', 'n_tokens_mistral': 1575, 'n_tokens_neox': 1550, 'n_words': 255}