1
0

Workflow.vue 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  1. <template>
  2. <div id="workflowengine">
  3. <NcSettingsSection :name="t('workflowengine', 'Available flows')"
  4. :doc-url="workflowDocUrl">
  5. <p v-if="isAdminScope" class="settings-hint">
  6. <a href="https://nextcloud.com/developer/">{{ t('workflowengine', 'For details on how to write your own flow, check out the development documentation.') }}</a>
  7. </p>
  8. <NcEmptyContent v-if="!isUserAdmin && mainOperations.length === 0"
  9. :name="t('workflowengine', 'No flows installed')"
  10. :description="!isUserAdmin ? t('workflowengine', 'Ask your administrator to install new flows.') : undefined">
  11. <template #icon>
  12. <NcIconSvgWrapper :svg="WorkflowOffSvg" :size="20" />
  13. </template>
  14. </NcEmptyContent>
  15. <transition-group v-else
  16. name="slide"
  17. tag="div"
  18. class="actions">
  19. <Operation v-for="operation in mainOperations"
  20. :key="operation.id"
  21. :operation="operation"
  22. @click.native="createNewRule(operation)" />
  23. <a v-if="showAppStoreHint"
  24. key="add"
  25. :href="appstoreUrl"
  26. class="actions__item colored more">
  27. <div class="icon icon-add" />
  28. <div class="actions__item__description">
  29. <h3>{{ t('workflowengine', 'More flows') }}</h3>
  30. <small>{{ t('workflowengine', 'Browse the App Store') }}</small>
  31. </div>
  32. </a>
  33. </transition-group>
  34. <div v-if="hasMoreOperations" class="actions__more">
  35. <NcButton @click="showMoreOperations = !showMoreOperations">
  36. <template #icon>
  37. <MenuUp v-if="showMoreOperations" :size="20" />
  38. <MenuDown v-else :size="20" />
  39. </template>
  40. {{ showMoreOperations ? t('workflowengine', 'Show less') : t('workflowengine', 'Show more') }}
  41. </NcButton>
  42. </div>
  43. </NcSettingsSection>
  44. <NcSettingsSection v-if="mainOperations.length > 0"
  45. :name="isAdminScope ? t('workflowengine', 'Configured flows') : t('workflowengine', 'Your flows')">
  46. <transition-group v-if="rules.length > 0" name="slide">
  47. <Rule v-for="rule in rules" :key="rule.id" :rule="rule" />
  48. </transition-group>
  49. <NcEmptyContent v-else :name="t('workflowengine', 'No flows configured')">
  50. <template #icon>
  51. <NcIconSvgWrapper :svg="WorkflowOffSvg" :size="20" />
  52. </template>
  53. </NcEmptyContent>
  54. </NcSettingsSection>
  55. </div>
  56. </template>
  57. <script>
  58. import Rule from './Rule.vue'
  59. import Operation from './Operation.vue'
  60. import NcButton from '@nextcloud/vue/dist/Components/NcButton.js'
  61. import NcEmptyContent from '@nextcloud/vue/dist/Components/NcEmptyContent.js'
  62. import NcIconSvgWrapper from '@nextcloud/vue/dist/Components/NcIconSvgWrapper.js'
  63. import NcSettingsSection from '@nextcloud/vue/dist/Components/NcSettingsSection.js'
  64. import { mapGetters, mapState } from 'vuex'
  65. import { generateUrl } from '@nextcloud/router'
  66. import { loadState } from '@nextcloud/initial-state'
  67. import MenuUp from 'vue-material-design-icons/MenuUp.vue'
  68. import MenuDown from 'vue-material-design-icons/MenuDown.vue'
  69. import WorkflowOffSvg from '../../img/workflow-off.svg?raw'
  70. const ACTION_LIMIT = 3
  71. const ADMIN_SCOPE = 0
  72. // const PERSONAL_SCOPE = 1
  73. export default {
  74. name: 'Workflow',
  75. components: {
  76. MenuDown,
  77. MenuUp,
  78. NcButton,
  79. NcEmptyContent,
  80. NcIconSvgWrapper,
  81. NcSettingsSection,
  82. Operation,
  83. Rule,
  84. },
  85. data() {
  86. return {
  87. showMoreOperations: false,
  88. appstoreUrl: generateUrl('settings/apps/workflow'),
  89. workflowDocUrl: loadState('workflowengine', 'doc-url'),
  90. WorkflowOffSvg,
  91. }
  92. },
  93. computed: {
  94. ...mapGetters({
  95. rules: 'getRules',
  96. }),
  97. ...mapState({
  98. appstoreEnabled: 'appstoreEnabled',
  99. scope: 'scope',
  100. operations: 'operations',
  101. }),
  102. hasMoreOperations() {
  103. return Object.keys(this.operations).length > ACTION_LIMIT
  104. },
  105. mainOperations() {
  106. if (this.showMoreOperations) {
  107. return Object.values(this.operations)
  108. }
  109. return Object.values(this.operations).slice(0, ACTION_LIMIT)
  110. },
  111. showAppStoreHint() {
  112. return this.appstoreEnabled && OC.isUserAdmin()
  113. },
  114. isUserAdmin() {
  115. return OC.isUserAdmin()
  116. },
  117. isAdminScope() {
  118. return this.scope === ADMIN_SCOPE
  119. },
  120. },
  121. mounted() {
  122. this.$store.dispatch('fetchRules')
  123. },
  124. methods: {
  125. createNewRule(operation) {
  126. this.$store.dispatch('createNewRule', operation)
  127. },
  128. },
  129. }
  130. </script>
  131. <style scoped lang="scss">
  132. #workflowengine {
  133. border-bottom: 1px solid var(--color-border);
  134. }
  135. .section {
  136. max-width: 100vw;
  137. h2.configured-flows {
  138. margin-top: 50px;
  139. margin-bottom: 0;
  140. }
  141. }
  142. .actions {
  143. display: flex;
  144. flex-wrap: wrap;
  145. max-width: 1200px;
  146. .actions__item {
  147. max-width: 280px;
  148. flex-basis: 250px;
  149. }
  150. }
  151. .actions__more {
  152. margin-bottom: 10px;
  153. }
  154. .slide-enter-active {
  155. -moz-transition-duration: 0.3s;
  156. -webkit-transition-duration: 0.3s;
  157. -o-transition-duration: 0.3s;
  158. transition-duration: 0.3s;
  159. -moz-transition-timing-function: ease-in;
  160. -webkit-transition-timing-function: ease-in;
  161. -o-transition-timing-function: ease-in;
  162. transition-timing-function: ease-in;
  163. }
  164. .slide-leave-active {
  165. -moz-transition-duration: 0.3s;
  166. -webkit-transition-duration: 0.3s;
  167. -o-transition-duration: 0.3s;
  168. transition-duration: 0.3s;
  169. -moz-transition-timing-function: cubic-bezier(0, 1, 0.5, 1);
  170. -webkit-transition-timing-function: cubic-bezier(0, 1, 0.5, 1);
  171. -o-transition-timing-function: cubic-bezier(0, 1, 0.5, 1);
  172. transition-timing-function: cubic-bezier(0, 1, 0.5, 1);
  173. }
  174. .slide-enter-to, .slide-leave {
  175. max-height: 500px;
  176. overflow: hidden;
  177. }
  178. .slide-enter, .slide-leave-to {
  179. overflow: hidden;
  180. max-height: 0;
  181. padding-top: 0;
  182. padding-bottom: 0;
  183. }
  184. @import "./../styles/operation";
  185. .actions__item.more {
  186. background-color: var(--color-background-dark);
  187. }
  188. </style>