vue-rule-script.html 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327
  1. <div id="app">
  2. <div class="app-wrapper" :class="{'is-preview':preview}">
  3. <div class="editor" v-if="!preview && !legacy" v-cloak>
  4. <div class="controls">
  5. <vue-button class="primary is-large" @click="clickPreview" :icon="icons.view">Preview</vue-button>
  6. </div>
  7. <div class="details">
  8. <div class="label-group">
  9. <label class="label" for="">
  10. <span>What is the community's name?</span>
  11. <div v-if="!edit">
  12. <input type="text" v-model="rule.name" @change="rule.ruleID = slugify(rule.name)">
  13. </div>
  14. <div v-else>
  15. <!-- <input type="text" v-model="rule.name" readonly> -->
  16. [[rule.name]]
  17. </div>
  18. </label>
  19. <label class="label">
  20. <span>Icon:</span>
  21. <div class="dropdown">
  22. <label v-for="(icon, iconName, idx) in ruleIcons" :key="idx"
  23. :class="{ selected: rule.icon == icon }">
  24. <input type="radio" id="" :selected="rule.icon == icon" :value="icon"
  25. v-model="rule.icon">
  26. <div><img :src="icon" :alt="iconName"></div>
  27. </label>
  28. <label class="default">
  29. <div><img :src="icons.blank"></div>
  30. </label>
  31. </div>
  32. </label>
  33. </div>
  34. <label class="label" for="">
  35. <span>Summarize its structure:</span>
  36. <textarea v-model="rule.summary"></textarea>
  37. </label>
  38. </div>
  39. <div class="rule__modules" :class="{ target: holding }">
  40. <label class="label" for="" v-if="rule.name">
  41. <icon :icon="rule.icon"></icon>[[rule.name]]
  42. </label>
  43. <div class="modules__dropzone modules__grid" :data-module-id="rule.ruleID" .module="rule"
  44. @drop.prevent="dropOnRule" @dragenter.prevent @dragover.prevent>
  45. <div v-if="rule.modules.length < 1">Drag rules from the library below here, or create your own.
  46. </div>
  47. <module v-for="module in rule.modules" :key="module" @click="handleClickEditModule" :module="module"
  48. draggable="true" @dragstart="rearrangeModule"></module>
  49. </div>
  50. </div>
  51. <div class="label-group is-mobile">
  52. <div class="module" @click="newCustomModule">
  53. <span class="plus"><img :src="icons.plus" alt="Add"></span>
  54. Create Custom Module
  55. </div>
  56. <div class="module-editor__empty">
  57. <small>Or click any module in categories like culture/decision/process/struture to start editing
  58. it.</small>
  59. </div>
  60. </div>
  61. <div class="module-editor__wrapper">
  62. <div class="module-editor">
  63. <module class="module-editor__label" hide-submodules :module="editor.module" draggable="false"
  64. v-if="editor.module.name"></module>
  65. <div class="module-editor__fields">
  66. <div class="label-group">
  67. <label class="label">
  68. <span>Module name:</span>
  69. <input class="input-stack" type="text" v-model="editor.module.name"
  70. @change="editor.module.moduleID = slugify(editor.module.name)">
  71. </label>
  72. <label class="label">
  73. <span>Icon:</span>
  74. <div class="dropdown">
  75. <label v-for="(icon, iconName, idx) in moduleIcons" :key="idx"
  76. :class="{ selected: editor.module.icon == icon }">
  77. <input type="radio" id="" :selected="editor.module.icon == icon" :value="icon"
  78. v-model="editor.module.icon">
  79. <div><img :src="icon" :alt="iconName"></div>
  80. </label>
  81. <label class="default">
  82. <div><img :src="icons.blank"></div>
  83. </label>
  84. </div>
  85. </label>
  86. </div>
  87. <label class="label">
  88. <span>Module Summary:</span>
  89. <textarea v-model="editor.module.summary"></textarea>
  90. </label>
  91. <label class="label configs">
  92. <table>
  93. <tr v-for="(value, key) in editor.module.config">
  94. <td>[[key]]</td>
  95. <td><input type="text" v-model="editor.module.config[key]" /></td>
  96. <td style="vertical-align: initial">
  97. <span class="config-button" @click="removeConfig([[key]])">
  98. <img :src="icons.minus" alt="Remove">
  99. </span>
  100. </td>
  101. </tr>
  102. <tr>
  103. <td><input id="newConfigKey" type="text" value="Configuration" /></td>
  104. <td>
  105. <input id="newConfigValue" type="text" value="Value" />
  106. </td>
  107. <td style="vertical-align: initial">
  108. <span class="config-button" @click="addConfig">
  109. <img :src="icons.plus" alt="Add">
  110. </span>
  111. </td>
  112. </tr>
  113. </table>
  114. </label>
  115. <!-- Working on custom module library
  116. <div class="label-group">
  117. <label class="label">
  118. <span>Module ID:</span>
  119. <input type="text" v-model="editor.module.moduleID">
  120. </label>
  121. <label class="label">
  122. <span>Type:</span>
  123. <input type="text" v-model="editor.module.type">
  124. </label>
  125. </div>
  126. <div class="modules__grid" v-if="editor.module.modules">
  127. <module
  128. v-for="(module, idx) in editor.module.modules"
  129. :key="idx"
  130. @click="handleClickEditModule"
  131. :module="module"
  132. ></module>
  133. </div>
  134. <label for="">
  135. <vue-button @click="saveEditor">Save</vue-button>
  136. </label>
  137. <label for="" v-if="customModules.includes(editor.module)">
  138. <vue-button @click="deleteModule(editor.module)">Delete</vue-button>
  139. </label> -->
  140. </div>
  141. </div>
  142. <div>
  143. <vue-button class="success" :icon="icons.plus" @click="clickAddModule"
  144. v-if="!moduleContains(editor.module) && editor.module">Add</vue-button>
  145. <vue-button class="danger" :icon="icons.minus" @click="clickRemoveModule"
  146. v-if="moduleContains(editor.module)">Remove</vue-button>
  147. </div>
  148. </div>
  149. <div class="modules">
  150. <div class="tabs">
  151. <div class="tab__control" v-for="(type, name) in moduleTypes" :key="name"
  152. @click="moduleLibrary = name" :class="{ active: moduleLibrary == name}">
  153. <img :src="type.icon" :alt="name"><span class="tab__control-name">[[ name ]]</span>
  154. </div>
  155. </div>
  156. <div class="tab__pane">
  157. <div class="modules__type" v-for="(type, name) in moduleTypes" :key="name"
  158. v-show="moduleLibrary == name" :test="name">
  159. <p>[[ type.question ]]</p>
  160. <div class="modules__grid">
  161. <module v-for="(module, index) in getModulesByType(name)" :key="index" :module="module"
  162. @click="handleClickCopyModule" has-grain draggable="true" @dragstart="startDragModule">
  163. </module>
  164. </div>
  165. </div>
  166. </div>
  167. </div>
  168. <div class="creator">
  169. <label class="label" for="">
  170. <span><img src="/assets/tabler_icons/pencil.svg"> Created By</span>
  171. <input type="text" v-model="rule.creator.name" placeholder="your name">
  172. </label>
  173. <label class="label" for="">
  174. <span><img src="/assets/tabler_icons/globe.svg"> Creator URL</span>
  175. <input type="text" v-model="rule.creator.url" placeholder="https://yourwebsite.org">
  176. </label>
  177. </div>
  178. </div>
  179. <div class="rule" v-show="preview" v-if="!legacy">
  180. <div v-if="rule.deleted !== 1">
  181. <div class="controls">
  182. <vue-button class="primary is-large" @click="clickPreview" :icon="icons.edit"
  183. v-if="!view">Edit</vue-button>
  184. </div>
  185. <h1>
  186. <icon :icon="rule.icon" v-if="rule.icon"></icon> [[rule.name]]
  187. </h1>
  188. <p>[[rule.summary]]</p>
  189. <div class="modules__grid" :data-module-id="rule.ruleID" .module="rule">
  190. <module-display v-for="module in rule.modules" :key="module" :module="module"></module-display>
  191. </div>
  192. <ul class="module-list">
  193. <module-list v-for="(module, index) in rule.modules" :key="index" :module="module"
  194. v-if="rule.modules"></module-list>
  195. </ul>
  196. <div class="rule__creator" v-if="rule.creator.name">
  197. Created By
  198. <img src="/assets/tabler_icons/pencil.svg">
  199. <span v-if="rule.creator.url"><a :href="rule.creator.url">[[rule.creator.name]]</a></span>
  200. <span v-else>[[rule.creator.name]]</span>
  201. </div>
  202. <div v-if="rule.forked==1" class="rule__creator">
  203. Fork History:
  204. <!-- <div style="white-space: normal;">
  205. <div v-for="ruleId1 in rule.edit_history" :key="ruleId1"
  206. style="display: inline-block; margin-right: 10px;">
  207. <a :href="getRuleLink(ruleId1)">[[
  208. getRuleName(ruleId1) ]]</a>
  209. <icon :icon="icons.arrow"></icon>
  210. </div>
  211. </div> -->
  212. <div v-for="(ruleId1, index) in rule.edit_history" :key="ruleId1" style="display: inline-block;">
  213. <a :href="getRuleLink(ruleId1)"> [[ getRuleName(ruleId1) ]]</a>&nbsp;&nbsp;
  214. <icon v-if="index < rule.edit_history.length - 1" :icon="icons.arrow"></icon>
  215. </div>
  216. </div>
  217. </div>
  218. <div v-else>
  219. <p>This Rule is deleted by owner</p>
  220. </div>
  221. </div>
  222. <div class="rule legacy" v-if="legacy && preview">
  223. <h1>[[rule.name]]</h1>
  224. <p>[[rule.summary]]</p>
  225. <div id="rule-builder" class="rulebuilder">
  226. <div id="module-input" class="rulebuilder_input modules__grid" v-html="rule.modules">
  227. </div>
  228. <div id="builder-field" class="rulebuilder_list">
  229. </div>
  230. </div>
  231. <div v-html="rule.rulewriter"></div>
  232. <div class="lineage" v-if="rule.lineage" v-html="rule.lineage"></div>
  233. <div class="rule__creator" v-if="rule.creatorName">
  234. Created By
  235. <img src="/assets/tabler_icons/pencil.svg">
  236. <span v-if="rule.creatorUrl"><a :href="rule.creatorUrl">[[rule.creatorName]]</a></span>
  237. <span v-else>[[rule.creatorName]]</span>
  238. </div>
  239. </div>
  240. <div class="btn-group" v-if="!legacy && !view">
  241. <!-- <vue-button class="primary is-large" @click="handleClickPublish" :icon="icons.publish" :loading="publishing">Publish</vue-button> -->
  242. <vue-button v-if="edit" class="primary is-large" @click="handleClickPublish" :icon="icons.edit"
  243. :loading="publishing">Edit</vue-button>
  244. <vue-button v-else class="primary is-large" @click="handleClickPublish" :icon="icons.publish"
  245. :loading="publishing">Publish</vue-button>
  246. <vue-button class="is-large" @click="handleClickDownload" :icon="icons.download">Download</vue-button>
  247. <vue-button class="is-large" @click="handleClickImport" :icon="icons.upload">Import <div class="btn-cover">
  248. coming soon!</div></vue-button>
  249. </div>
  250. <div v-if="rule.deleted !== 1">
  251. <div class="btn-group" v-if="view && !legacy">
  252. <vue-button class="primary is-large" @click="clickPreview" :icon="icons.fork">Fork &amp;
  253. Edit</vue-button>
  254. <vue-button class="primary is-large" v-if="isOwner" @click="clickPreviewEdit" :icon="icons.edit">Edit
  255. </vue-button>
  256. <vue-button class="primary is-large" v-if="isAdmin" @click="clickDelete" :icon="icons.delete">Delete
  257. </vue-button>
  258. <vue-button class="is-large" @click="handleClickDownload" :icon="icons.download">Download</vue-button>
  259. </div>
  260. </div>
  261. </div>
  262. <div id="rule-export" v-show="false" v-if="!legacy">
  263. <h1>[[rule.name]]</h1>
  264. <p>[[rule.summary]]</p>
  265. <ul class="module-list">
  266. <module-list v-for="(module, index) in rule.modules" :key="index" :module="module" v-if="rule.modules"
  267. hide-icon></module-list>
  268. </ul>
  269. <hr>
  270. <h2>Created By</h2>
  271. <p v-if="rule.creator.url"><a :href="rule.creator.url">[[rule.creator.name]]</a></p>
  272. <p v-else>[[rule.creator.name]]</p>
  273. </div>
  274. </div>
  275. <script src="/assets/js/vue.global.js"></script>
  276. <script src="/assets/DragDropTouch.js"></script>
  277. <script src="https://unpkg.com/stein-js-client"></script>
  278. <script src="https://cdnjs.cloudflare.com/ajax/libs/js-yaml/4.1.0/js-yaml.min.js" defer
  279. integrity="sha512-CSBhVREyzHAjAFfBlIBakjoRUKp5h7VSweP0InR/pAJyptH7peuhCsqAI/snV+TwZmXZqoUklpXp6R6wMnYf5Q=="
  280. crossorigin="anonymous" referrerpolicy="no-referrer"></script>
  281. <script src="https://unpkg.com/turndown/dist/turndown.js" defer></script>
  282. <script>
  283. let global = {};
  284. global.modules = [
  285. {% assign modules_array = site.modules | sort: "type" %}
  286. {% for module in modules_array %}
  287. {
  288. name: "{{ module.title | escape }}",
  289. url: "{{ site.baseurl }}{{ module.permalink }}",
  290. moduleID: "{{ module.slug }}",
  291. icon: "{{ site.data.module_types[module.type].icon | default: 'null'}}",
  292. summary: "{{ module.summary }}",
  293. type: "{{ module.type }}",
  294. content: `{{ module.content | markdownify }}`,
  295. {% if module.config %}
  296. config: {
  297. {% for config in module.config %}
  298. "{{ config[0] }}": "{{ config[1] }}"
  299. {% unless forloop.last %}, {% endunless %}
  300. {% endfor %}
  301. },
  302. {% endif %}
  303. readonly: true,
  304. modules: []
  305. } {% unless forloop.last %}, {% endunless %}
  306. {% endfor %}
  307. ];
  308. // global.url = "{{ site.url }}{{ site.baseurl }}";
  309. global.url = "https://communityrule.info";
  310. global.rule = {{ page.rule | jsonify }};
  311. </script>
  312. <script src="/assets/js/vue.rules.js"></script>