generator-folklore 3.0.3 → 3.0.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (205) hide show
  1. package/lib/generators/app/index.js +3 -51
  2. package/lib/generators/babel/index.js +28 -101
  3. package/lib/generators/babel/templates/config.js +16 -0
  4. package/lib/generators/browserslist/index.js +4 -9
  5. package/lib/generators/build/index.js +40 -29
  6. package/lib/generators/cli/index.js +92 -0
  7. package/lib/generators/cli/templates/cli.js +22 -0
  8. package/lib/generators/cli/templates/commands/default.js +16 -0
  9. package/lib/generators/docs/index.js +1 -2
  10. package/lib/generators/editorconfig/index.js +12 -22
  11. package/lib/generators/eslint/index.js +12 -13
  12. package/lib/generators/{html → html-project}/index.js +60 -73
  13. package/lib/generators/{html → html-project}/templates/folklore.png +0 -0
  14. package/lib/generators/{html → html-project}/templates/gitignore +0 -0
  15. package/lib/generators/{html → html-project}/templates/index.html.ejs +4 -1
  16. package/lib/generators/intl/index.js +93 -0
  17. package/lib/generators/laravel/index.js +5 -5
  18. package/lib/generators/laravel-mediatheque/index.js +133 -0
  19. package/lib/generators/laravel-mediatheque/templates/app/Models/Media.php +9 -0
  20. package/lib/generators/laravel-mediatheque/templates/app/Models/MediaFile.php +9 -0
  21. package/lib/generators/laravel-panneau/index.js +49 -28
  22. package/lib/generators/laravel-panneau/templates/app/Contracts/Repositories/Pages.php +19 -0
  23. package/lib/generators/laravel-panneau/templates/app/Contracts/Resources/Blocks/Text.php +10 -0
  24. package/lib/generators/laravel-panneau/templates/app/Contracts/Resources/Page.php +10 -0
  25. package/lib/generators/laravel-panneau/templates/app/Contracts/Resources/Pages/Home.php +9 -0
  26. package/lib/generators/laravel-panneau/templates/app/Http/Resources/BlockResource.php +37 -0
  27. package/lib/generators/laravel-panneau/templates/app/Http/Resources/BlocksCollection.php +8 -0
  28. package/lib/generators/laravel-panneau/templates/app/Http/Resources/PageResource.php +47 -0
  29. package/lib/generators/laravel-panneau/templates/app/Http/Resources/PagesCollection.php +10 -0
  30. package/lib/generators/laravel-panneau/templates/app/Models/Block.php +3 -13
  31. package/lib/generators/laravel-panneau/templates/app/Models/Page.php +3 -60
  32. package/lib/generators/laravel-panneau/templates/app/Panneau/Composers/AppComposer.php +50 -0
  33. package/lib/generators/laravel-panneau/templates/app/Panneau/Fields/Block.php +22 -0
  34. package/lib/generators/laravel-panneau/templates/app/Panneau/Fields/Blocks.php +87 -0
  35. package/lib/generators/laravel-panneau/templates/app/Panneau/Fields/Page.php +51 -0
  36. package/lib/generators/laravel-panneau/templates/app/Panneau/Fields/PageSlug.php +34 -0
  37. package/lib/generators/laravel-panneau/templates/app/Panneau/Fields/PageSlugLocalized.php +18 -0
  38. package/lib/generators/laravel-panneau/templates/app/Panneau/Http/Controllers/AccountController.php +41 -0
  39. package/lib/generators/laravel-panneau/templates/app/Panneau/Http/Controllers/Controller.php +19 -0
  40. package/lib/generators/laravel-panneau/templates/app/Panneau/Http/Controllers/HomeController.php +16 -0
  41. package/lib/generators/laravel-panneau/templates/app/Panneau/Http/Controllers/PagesController.php +24 -0
  42. package/lib/generators/laravel-panneau/templates/app/Panneau/Http/Controllers/UploadController.php +27 -0
  43. package/lib/generators/laravel-panneau/templates/app/Panneau/Http/Controllers/UsersController.php +32 -0
  44. package/lib/generators/laravel-panneau/templates/app/Panneau/Http/Requests/AccountUpdateRequest.php +29 -0
  45. package/lib/generators/laravel-panneau/templates/app/Panneau/Http/Requests/UploadRequest.php +29 -0
  46. package/lib/generators/laravel-panneau/templates/app/Panneau/Http/Resources/BlockResource.php +39 -0
  47. package/lib/generators/laravel-panneau/templates/app/Panneau/Http/Resources/BlocksCollection.php +8 -0
  48. package/lib/generators/laravel-panneau/templates/app/Panneau/Http/Resources/PageResource.php +56 -0
  49. package/lib/generators/laravel-panneau/templates/app/Panneau/Http/Resources/PagesCollection.php +10 -0
  50. package/lib/generators/laravel-panneau/templates/app/Panneau/Http/Resources/UserResource.php +24 -0
  51. package/lib/generators/laravel-panneau/templates/app/Panneau/PanneauServiceProvider.php +48 -0
  52. package/lib/generators/laravel-panneau/templates/app/Panneau/Policies/PanneauPolicy.php +32 -0
  53. package/lib/generators/laravel-panneau/templates/app/Panneau/Resources/Blocks/BlockWithBlocks.php +110 -0
  54. package/lib/generators/laravel-panneau/templates/app/Panneau/Resources/Blocks/TextBlock.php +27 -0
  55. package/lib/generators/laravel-panneau/templates/app/Panneau/Resources/Blocks.php +42 -0
  56. package/lib/generators/laravel-panneau/templates/app/Panneau/Resources/Pages/Page.php +28 -0
  57. package/lib/generators/laravel-panneau/templates/app/Panneau/Resources/Pages.php +92 -0
  58. package/lib/generators/laravel-panneau/templates/app/Panneau/Resources/Users.php +57 -0
  59. package/lib/generators/laravel-panneau/templates/app/Repositories/Pages.php +42 -0
  60. package/lib/generators/laravel-panneau/templates/app/Resources/Blocks/TextBlock.php +14 -0
  61. package/lib/generators/laravel-panneau/templates/app/Resources/Page.php +10 -0
  62. package/lib/generators/laravel-panneau/templates/app/Resources/Pages/HomePage.php +10 -0
  63. package/lib/generators/laravel-panneau/templates/app.blade.php +8 -0
  64. package/lib/generators/laravel-panneau/templates/index.js +32 -0
  65. package/lib/generators/laravel-panneau/templates/lang/en/panneau.php +62 -0
  66. package/lib/generators/laravel-panneau/templates/lang/fr/panneau.php +62 -0
  67. package/lib/generators/laravel-panneau/templates/layout.blade.php +17 -48
  68. package/lib/generators/laravel-panneau/templates/resources/assets/js/components/Panneau.jsx +68 -0
  69. package/lib/generators/{js/templates/src/lib/.gitkeep → laravel-panneau/templates/resources/assets/js/components/panneau/fields/PageSlug.jsx} +0 -0
  70. package/lib/generators/laravel-panneau/templates/resources/assets/js/components/panneau/fields/PageSlugLocalized.jsx +43 -0
  71. package/lib/generators/laravel-panneau/templates/resources/assets/js/components/panneau/fields/index.js +2 -0
  72. package/lib/generators/laravel-panneau/templates/resources/assets/styles/panneau.scss +2 -0
  73. package/lib/generators/laravel-panneau/templates/routes.php +30 -0
  74. package/lib/generators/laravel-project/index.js +504 -0
  75. package/lib/generators/laravel-project/templates/env +41 -0
  76. package/lib/generators/laravel-project/templates/laravel/app/Composers/AppComposer.php +48 -0
  77. package/lib/generators/laravel-project/templates/laravel/app/Composers/IntlComposer.php +10 -0
  78. package/lib/generators/laravel-project/templates/laravel/app/Composers/MetaComposer.php +48 -0
  79. package/lib/generators/laravel-project/templates/laravel/app/Composers/RoutesComposer.php +19 -0
  80. package/lib/generators/laravel-project/templates/laravel/app/Contracts/Resources/User.php +10 -0
  81. package/lib/generators/laravel-project/templates/laravel/app/Http/Controllers/HomeController.php +18 -0
  82. package/lib/generators/laravel-project/templates/laravel/app/Http/Middleware/TrustProxies.php +28 -0
  83. package/lib/generators/laravel-project/templates/laravel/app/Http/Resources/UserResource.php +21 -0
  84. package/lib/generators/laravel-project/templates/laravel/app/Models/User.php +50 -0
  85. package/lib/generators/laravel-project/templates/laravel/app/Providers/AppServiceProvider.php +45 -0
  86. package/lib/generators/laravel-project/templates/laravel/app/Providers/RouteServiceProvider.php +64 -0
  87. package/lib/generators/laravel-project/templates/laravel/app/Providers/ViewServiceProvider.php +33 -0
  88. package/lib/generators/laravel-project/templates/laravel/app/Repositories/Users.php +36 -0
  89. package/lib/generators/laravel-project/templates/laravel/app/Resources/User.php +11 -0
  90. package/lib/generators/laravel-project/templates/laravel/config/app.php +216 -0
  91. package/lib/generators/laravel-project/templates/laravel/config/auth.php +116 -0
  92. package/lib/generators/laravel-project/templates/laravel/config/services.php +39 -0
  93. package/lib/generators/laravel-project/templates/laravel/lang/en/content.php +5 -0
  94. package/lib/generators/laravel-project/templates/laravel/lang/en/errors.php +17 -0
  95. package/lib/generators/laravel-project/templates/laravel/lang/en/meta.php +11 -0
  96. package/lib/generators/laravel-project/templates/laravel/lang/en/routes.php +4 -0
  97. package/lib/generators/laravel-project/templates/laravel/lang/fr/auth.php +19 -0
  98. package/lib/generators/laravel-project/templates/laravel/lang/fr/content.php +5 -0
  99. package/lib/generators/laravel-project/templates/laravel/lang/fr/errors.php +17 -0
  100. package/lib/generators/laravel-project/templates/laravel/lang/fr/meta.php +11 -0
  101. package/lib/generators/laravel-project/templates/laravel/lang/fr/pagination.php +19 -0
  102. package/lib/generators/laravel-project/templates/laravel/lang/fr/passwords.php +22 -0
  103. package/lib/generators/laravel-project/templates/laravel/lang/fr/routes.php +12 -0
  104. package/lib/generators/laravel-project/templates/laravel/lang/fr/validation.php +146 -0
  105. package/lib/generators/{js/templates/styles → laravel-project/templates/laravel/resources/assets/fonts}/.gitkeep +0 -0
  106. package/lib/generators/{laravel-panneau/templates/app/Schemas/Fields → laravel-project/templates/laravel/resources/assets/img}/.gitkeep +0 -0
  107. package/lib/generators/laravel-project/templates/laravel/resources/assets/img/folklore.png +0 -0
  108. package/lib/generators/laravel-project/templates/laravel/resources/views/analytics/body.blade.php +3 -0
  109. package/lib/generators/laravel-project/templates/laravel/resources/views/analytics/gpt.blade.php +16 -0
  110. package/lib/generators/laravel-project/templates/laravel/resources/views/analytics/head.blade.php +1 -0
  111. package/lib/generators/laravel-project/templates/laravel/resources/views/app.blade.php +8 -0
  112. package/lib/generators/laravel-project/templates/laravel/resources/views/errors/401.blade.php +8 -0
  113. package/lib/generators/laravel-project/templates/laravel/resources/views/errors/403.blade.php +8 -0
  114. package/lib/generators/laravel-project/templates/laravel/resources/views/errors/404.blade.php +8 -0
  115. package/lib/generators/laravel-project/templates/laravel/resources/views/errors/500.blade.php +8 -0
  116. package/lib/generators/laravel-project/templates/laravel/resources/views/layout.blade.php +33 -0
  117. package/lib/generators/laravel-project/templates/laravel/resources/views/meta/all.blade.php +4 -0
  118. package/lib/generators/laravel-project/templates/laravel/resources/views/meta/base.blade.php +11 -0
  119. package/lib/generators/laravel-project/templates/laravel/resources/views/meta/facebook.blade.php +4 -0
  120. package/lib/generators/laravel-project/templates/laravel/resources/views/meta/opengraph.blade.php +9 -0
  121. package/lib/generators/laravel-project/templates/laravel/resources/views/meta/twitter.blade.php +5 -0
  122. package/lib/generators/laravel-project/templates/laravel/routes/web.php +12 -0
  123. package/lib/generators/lerna-package/index.js +1 -3
  124. package/lib/generators/lerna-repository/index.js +1 -3
  125. package/lib/generators/node-project/index.js +164 -0
  126. package/lib/generators/node-project/templates/index.js +0 -0
  127. package/lib/generators/npm-package/index.js +3 -5
  128. package/lib/generators/prettier/index.js +19 -6
  129. package/lib/generators/prettier/templates/prettierrc.json +3 -1
  130. package/lib/generators/{js → react-app}/index.js +22 -52
  131. package/lib/generators/{js → react-app}/templates/_package.json +0 -0
  132. package/lib/generators/react-app/templates/index.js +23 -0
  133. package/lib/generators/react-app/templates/src/components/App.jsx +46 -0
  134. package/lib/generators/react-app/templates/src/components/Container.jsx +40 -0
  135. package/lib/generators/{js → react-app}/templates/src/components/buttons/Button.jsx +4 -18
  136. package/lib/generators/react-app/templates/src/components/layouts/Main.jsx +27 -0
  137. package/lib/generators/react-app/templates/src/components/menus/Menu.jsx +62 -0
  138. package/lib/generators/{js → react-app}/templates/src/components/pages/Error.jsx +10 -14
  139. package/lib/generators/react-app/templates/src/components/pages/Home.jsx +32 -0
  140. package/lib/generators/{js → react-app}/templates/src/components/partials/PageMeta.jsx +11 -11
  141. package/lib/generators/{js → react-app}/templates/src/contexts/KeysContext.jsx +0 -0
  142. package/lib/generators/react-app/templates/src/lib/.gitkeep +0 -0
  143. package/lib/generators/{js → react-app}/templates/src/lib/PropTypes.js +0 -0
  144. package/lib/generators/{js → react-app}/templates/src/lib/utils.js +0 -0
  145. package/lib/generators/react-app/templates/src/polyfills/index.js +6 -0
  146. package/lib/generators/react-app/templates/src/polyfills/intl-en.js +2 -0
  147. package/lib/generators/react-app/templates/src/polyfills/intl-fr.js +2 -0
  148. package/lib/generators/react-app/templates/src/polyfills/should.js +14 -0
  149. package/lib/generators/react-app/templates/styles/.gitkeep +0 -0
  150. package/lib/generators/{js/templates/styles/buttons/button.scss → react-app/templates/styles/buttons/button.module.scss} +1 -0
  151. package/lib/generators/{js/templates/styles/layouts/main.scss → react-app/templates/styles/layouts/main.module.scss} +0 -0
  152. package/lib/generators/{js/templates/styles/menus/menu.scss → react-app/templates/styles/menus/menu.module.scss} +0 -0
  153. package/lib/generators/{js/templates/styles/pages/error.scss → react-app/templates/styles/pages/error.module.scss} +0 -0
  154. package/lib/generators/{js/templates/styles/pages/home.scss → react-app/templates/styles/pages/home.module.scss} +0 -0
  155. package/lib/generators/rollup/index.js +54 -0
  156. package/lib/generators/rollup/templates/config.js +50 -0
  157. package/lib/generators/scss/index.js +3 -16
  158. package/lib/generators/scss/templates/{main.scss → styles.scss} +0 -0
  159. package/lib/generators/server/index.js +81 -0
  160. package/lib/generators/server/templates/server.js +59 -0
  161. package/lib/generators/storybook/index.js +1 -7
  162. package/lib/generators/stylelint/index.js +13 -14
  163. package/lib/lib/generator.js +9 -0
  164. package/lib/lib/utils.js +17 -0
  165. package/package.json +2 -2
  166. package/lib/generators/babel/templates/babel-preset-react.js +0 -7
  167. package/lib/generators/babel/templates/babel-preset.js +0 -57
  168. package/lib/generators/babel/templates/babelrc +0 -5
  169. package/lib/generators/babel/templates/utils/processScss.js +0 -10
  170. package/lib/generators/babel/templates/utils/transformRequireIgnore.js +0 -80
  171. package/lib/generators/html/templates/index.js +0 -9
  172. package/lib/generators/html/templates/root.js +0 -23
  173. package/lib/generators/html/templates/utils.js +0 -7
  174. package/lib/generators/js/templates/browserslistrc +0 -9
  175. package/lib/generators/js/templates/config.js +0 -33
  176. package/lib/generators/js/templates/index.js +0 -41
  177. package/lib/generators/js/templates/src/actions/LayoutActions.js +0 -12
  178. package/lib/generators/js/templates/src/actions/SiteActions.js +0 -22
  179. package/lib/generators/js/templates/src/components/App.jsx +0 -52
  180. package/lib/generators/js/templates/src/components/Root.jsx +0 -70
  181. package/lib/generators/js/templates/src/components/layouts/Main.jsx +0 -52
  182. package/lib/generators/js/templates/src/components/menus/Menu.jsx +0 -60
  183. package/lib/generators/js/templates/src/components/messages/Success.jsx +0 -36
  184. package/lib/generators/js/templates/src/components/pages/Home.jsx +0 -32
  185. package/lib/generators/js/templates/src/components/partials/Label.jsx +0 -32
  186. package/lib/generators/js/templates/src/reducers/LayoutReducer.js +0 -32
  187. package/lib/generators/js/templates/src/reducers/SiteReducer.js +0 -36
  188. package/lib/generators/js/templates/src/reducers/index.js +0 -7
  189. package/lib/generators/js/templates/src/vendor/polyfills/intl-en.js +0 -2
  190. package/lib/generators/js/templates/src/vendor/polyfills/intl-fr.js +0 -2
  191. package/lib/generators/laravel-panneau/templates/_composer.json +0 -6
  192. package/lib/generators/laravel-panneau/templates/_package.json +0 -11
  193. package/lib/generators/laravel-panneau/templates/app/Http/Controllers/Panneau/HomeController.php +0 -14
  194. package/lib/generators/laravel-panneau/templates/app/Http/Controllers/Panneau/PagesController.php +0 -11
  195. package/lib/generators/laravel-panneau/templates/app/Models/Mediatheque/File.php +0 -13
  196. package/lib/generators/laravel-panneau/templates/app/Models/Mediatheque/Picture.php +0 -13
  197. package/lib/generators/laravel-panneau/templates/app/Models/Mediatheque/Video.php +0 -34
  198. package/lib/generators/laravel-panneau/templates/app/Providers/PanneauServiceProvider.php +0 -23
  199. package/lib/generators/laravel-panneau/templates/app/Reducers/SlugExtractReducer.php +0 -18
  200. package/lib/generators/laravel-panneau/templates/app/Resources/Pages.php +0 -54
  201. package/lib/generators/laravel-panneau/templates/app/Schemas/Blocks/Base.php +0 -22
  202. package/lib/generators/laravel-panneau/templates/app/Schemas/Bubbles/Base.php +0 -22
  203. package/lib/generators/laravel-panneau/templates/app/Schemas/Pages/Base.php +0 -36
  204. package/lib/generators/laravel-panneau/templates/resources/lang/en/panneau.php +0 -12
  205. package/lib/generators/laravel-panneau/templates/resources/lang/fr/panneau.php +0 -12
@@ -0,0 +1,10 @@
1
+ <?php
2
+
3
+ namespace App\Contracts\Resources;
4
+
5
+ use Folklore\Contracts\Resources\Page as BasePage;
6
+
7
+ interface Page extends BasePage
8
+ {
9
+
10
+ }
@@ -0,0 +1,9 @@
1
+ <?php
2
+
3
+ namespace App\Contracts\Resources\Pages;
4
+
5
+ use App\Contracts\Resources\Page as BasePage;
6
+
7
+ interface Home extends BasePage
8
+ {
9
+ }
@@ -0,0 +1,37 @@
1
+ <?php
2
+
3
+ namespace App\Http\Resources;
4
+
5
+ use Illuminate\Http\Resources\Json\JsonResource;
6
+ use App\Contracts\Resources\HasBlocks;
7
+ use Folklore\Http\Resources\LocalizedResource;
8
+ use App\Contracts\Resources\Blocks\Text as TextBlock;
9
+
10
+ class BlockResource extends JsonResource
11
+ {
12
+ /**
13
+ * Transform the resource into an array.
14
+ *
15
+ * @param \Illuminate\Http\Request $request
16
+ * @return array
17
+ */
18
+ public function toArray($request)
19
+ {
20
+ $type = $this->type();
21
+ $locale = $request->locale();
22
+ return [
23
+ 'id' => $this->id(),
24
+ 'type' => $type,
25
+ 'blocks' => $this->when($this->resource instanceof HasBlocks, function () {
26
+ $blocks = $this->blocks();
27
+ return !is_null($blocks) ? new BlocksCollection($blocks) : [];
28
+ }),
29
+
30
+ $this->mergeWhen($this->resource instanceof TextBlock, function () use ($locale) {
31
+ return [
32
+ 'body' => $this->body($locale),
33
+ ];
34
+ }),
35
+ ];
36
+ }
37
+ }
@@ -0,0 +1,8 @@
1
+ <?php
2
+
3
+ namespace App\Http\Resources;
4
+
5
+ class BlocksCollection extends Collection
6
+ {
7
+ public $collects = BlockResource::class;
8
+ }
@@ -0,0 +1,47 @@
1
+ <?php
2
+
3
+ namespace App\Http\Resources;
4
+
5
+ use Illuminate\Http\Resources\Json\JsonResource;
6
+ use App\Http\Resources\Medias\ImageResource;
7
+ use App\Contracts\Resources\Page;
8
+ use App\Contracts\Resources\HasBlocks;
9
+ use App\Contracts\Resources\Pages\Home as HomePage;
10
+
11
+ class PageResource extends JsonResource
12
+ {
13
+ /**
14
+ * Transform the resource into an array.
15
+ *
16
+ * @param \Illuminate\Http\Request $request
17
+ * @return array
18
+ */
19
+ public function toArray($request)
20
+ {
21
+ $locale = $request->locale();
22
+ return [
23
+ 'id' => $this->id(),
24
+ 'type' => $this->type(),
25
+ 'published' => $this->published(),
26
+ 'title' => $this->title($locale),
27
+ 'description' => $this->description($locale),
28
+ 'slug' => $this->slug($locale),
29
+ 'image' => !is_null($image) ? new ImageResource($image) : null,
30
+ 'parent' =>
31
+ !is_null($parent) && $parent instanceof Page
32
+ ? new ParentPageResource($parent)
33
+ : null,
34
+
35
+ $this->mergeWhen($this->resource instanceof HasBlocks, function () {
36
+ $blocks = $this->blocks();
37
+ return [
38
+ 'blocks' => !is_null($blocks) ? new BlocksCollection($blocks) : [],
39
+ ];
40
+ }),
41
+
42
+ $this->mergeWhen($this->resource instanceof HomePage, function () {
43
+ return [];
44
+ }),
45
+ ];
46
+ }
47
+ }
@@ -0,0 +1,10 @@
1
+ <?php
2
+
3
+ namespace App\Http\Resources;
4
+
5
+ use Folklore\Http\Resources\Collection;
6
+
7
+ class PagesCollection extends Collection
8
+ {
9
+ public $collects = PageResource::class;
10
+ }
@@ -2,21 +2,11 @@
2
2
 
3
3
  namespace App\Models;
4
4
 
5
- use Folklore\Panneau\Models\Block as BaseBlock;
5
+ use Folklore\Models\Block as BaseBlock;
6
6
 
7
7
  class Block extends BaseBlock
8
8
  {
9
- protected $hidden = [
10
- 'pictures',
11
- 'audios',
12
- 'videos',
13
- 'pivot',
14
- 'deleted_at'
15
- ];
16
-
17
- protected $jsonSchemasReducers = [
18
- \Folklore\Panneau\Reducers\BlocksReducer::class,
19
- \Folklore\Panneau\Reducers\PagesReducer::class,
20
- \Folklore\Panneau\Reducers\MediasReducer::class,
9
+ protected $typeResources = [
10
+ 'text' => \App\Resources\Blocks\TextBlock::class,
21
11
  ];
22
12
  }
@@ -2,68 +2,11 @@
2
2
 
3
3
  namespace App\Models;
4
4
 
5
- use Folklore\Panneau\Models\Page as BasePage;
6
- use Folklore\Panneau\Contracts\Page as PageContract;
5
+ use Folklore\Models\Page as BasePage;
7
6
 
8
7
  class Page extends BasePage
9
8
  {
10
- protected $hidden = [
11
- 'slug_fr',
12
- 'slug_en',
13
- 'blocks',
14
- 'pages',
15
- 'pictures',
16
- 'audios',
17
- 'videos',
18
- 'order',
19
- 'deleted_at'
9
+ protected $typeResources = [
10
+ 'text' => \App\Resources\Pages\HomePage::class,
20
11
  ];
21
-
22
- protected $appends = [
23
- 'url',
24
- 'urls',
25
- ];
26
-
27
- protected $jsonSchemasReducers = [
28
- \Folklore\Panneau\Reducers\BlocksReducer::class,
29
- \Folklore\Panneau\Reducers\PagesReducer::class,
30
- \Folklore\Panneau\Reducers\MediasReducer::class,
31
- \Folklore\Panneau\Reducers\SlugReducer::class,
32
- \App\Reducers\SlugExtractReducer::class,
33
- ];
34
-
35
- protected function getUrlAttribute()
36
- {
37
- return $this->getUrl();
38
- }
39
-
40
- protected function getUrlsAttribute()
41
- {
42
- $urls = [];
43
- $locales = config('locale.locales', []);
44
- foreach ($locales as $locale) {
45
- $urls[$locale] = $this->getUrl($locale);
46
- }
47
- return $urls;
48
- }
49
-
50
- protected function getUrl($locale = null)
51
- {
52
- if (is_null($locale)) {
53
- $locale = app()->getLocale();
54
- }
55
- return '';
56
- // return route('pages.show.'.$locale, [array_get($this->attributes, 'slug_'.$locale)]);
57
- }
58
-
59
- /**
60
- * Get the route key for the model.
61
- *
62
- * @return string
63
- */
64
- public function getRouteKeyName()
65
- {
66
- $locale = app()->getLocale();
67
- return 'slug_'.$locale;
68
- }
69
12
  }
@@ -0,0 +1,50 @@
1
+ <?php
2
+
3
+ namespace App\Panneau\Composers;
4
+
5
+ use Illuminate\Http\Request;
6
+ use Illuminate\View\View;
7
+ use App\Panneau\Http\Resources\UserResource;
8
+
9
+ class AppComposer
10
+ {
11
+ /**
12
+ * The request
13
+ *
14
+ * @var \Illuminate\Http\Request
15
+ */
16
+ protected $request;
17
+
18
+ protected $panneau;
19
+
20
+ /**
21
+ * Create a new profile composer.
22
+ *
23
+ * @param \Illuminate\Http\Request $request
24
+ * @return void
25
+ */
26
+ public function __construct(Request $request)
27
+ {
28
+ $this->request = $request;
29
+ }
30
+
31
+ /**
32
+ * Bind data to the view.
33
+ *
34
+ * @param View $view
35
+ * @return void
36
+ */
37
+ public function compose(View $view)
38
+ {
39
+ $user = $this->request->user();
40
+
41
+ $view->props = array_merge(isset($view->props) ? $view->props : [], [
42
+ 'user' => !is_null($user) ? new UserResource($user) : null,
43
+ 'isPanneau' => true,
44
+ 'statusCode' => $view->statusCode,
45
+ 'pubnubNamespace' => config('services.pubnub.namespace'),
46
+ 'pubnubPublishKey' => config('services.pubnub.publish_key'),
47
+ 'pubnubSubscribeKey' => config('services.pubnub.subscribe_key'),
48
+ ]);
49
+ }
50
+ }
@@ -0,0 +1,22 @@
1
+ <?php
2
+
3
+ namespace App\Panneau\Fields;
4
+
5
+ use Panneau\Fields\ResourceItem;
6
+
7
+ class Block extends ResourceItem
8
+ {
9
+ public function resource(): string
10
+ {
11
+ return 'blocks';
12
+ }
13
+
14
+ public function attributes(): ?array
15
+ {
16
+ return array_merge(parent::attributes(), [
17
+ 'placeholder' => trans('panneau.fields.blocks_placeholder'),
18
+ 'itemLabelPath' => 'title',
19
+ 'itemDescriptionPath' => null,
20
+ ]);
21
+ }
22
+ }
@@ -0,0 +1,87 @@
1
+ <?php
2
+
3
+ namespace App\Panneau\Fields;
4
+
5
+ use Panneau\Fields\Items;
6
+ use Panneau\Fields\ResourceItem;
7
+ use App\Panneau\Resources\Blocks\BlockWithBlocks;
8
+
9
+ class Blocks extends Items
10
+ {
11
+ protected $currentDepth = 0;
12
+
13
+ protected $maxDepth = null;
14
+
15
+ protected $excludeTypes = [];
16
+
17
+ public function itemField(): ?string
18
+ {
19
+ return Block::class;
20
+ }
21
+
22
+ public function attributes(): ?array
23
+ {
24
+ // With types
25
+ $itemField = $this->itemField();
26
+ $itemField = !is_null($itemField) ? resolve($itemField) : null;
27
+ $itemResource =
28
+ !is_null($itemField) && $itemField instanceof ResourceItem
29
+ ? $itemField->makeResource()
30
+ : null;
31
+ $resourceTypes =
32
+ !is_null($itemResource) && $itemResource->hasTypes() ? $itemResource->getTypes() : null;
33
+
34
+ $attributes = [
35
+ 'withoutFormGroup' => true,
36
+ 'addItemLabel' => trans('panneau.fields.add_block'),
37
+ 'noItemLabel' => trans('panneau.fields.no_blocks'),
38
+ 'itemLabel' => trans('panneau.fields.block'),
39
+ 'withoutSort' => false,
40
+ ];
41
+
42
+ if (!is_null($resourceTypes)) {
43
+ $attributes['types'] = $resourceTypes
44
+ ->filter(function ($type) {
45
+ $key = get_class($type);
46
+ return !in_array($key, $this->excludeTypes);
47
+ })
48
+ ->map(function ($type) {
49
+ $hasBlocks = collect($type->fields())->contains(function ($field) {
50
+ return $field instanceof self;
51
+ });
52
+ if (isset($this->maxDepth) && $hasBlocks) {
53
+ return new BlockWithBlocks($type, $this->currentDepth + 1);
54
+ }
55
+ return $type;
56
+ })
57
+ ->filter(function ($type) {
58
+ if (isset($this->maxDepth) && $type instanceof BlockWithBlocks) {
59
+ return $type->currentDepth() < $this->maxDepth;
60
+ }
61
+ return true;
62
+ })
63
+ ->values()
64
+ ->toArray();
65
+ }
66
+
67
+ return $attributes;
68
+ }
69
+
70
+ public function maxDepth($depth)
71
+ {
72
+ $this->maxDepth = $depth;
73
+ return $this;
74
+ }
75
+
76
+ public function currentDepth($depth)
77
+ {
78
+ $this->currentDepth = $depth;
79
+ return $this;
80
+ }
81
+
82
+ public function withoutType($type)
83
+ {
84
+ $this->excludeTypes[] = is_object($type) ? get_class($type) : $type;
85
+ return $this;
86
+ }
87
+ }
@@ -0,0 +1,51 @@
1
+ <?php
2
+
3
+ namespace App\Panneau\Fields;
4
+
5
+ use Panneau\Fields\ResourceItem;
6
+
7
+ class Page extends ResourceItem
8
+ {
9
+ protected $query = [
10
+ 'paginated' => false,
11
+ ];
12
+
13
+ protected $pageTypes = [];
14
+
15
+ public function resource(): string
16
+ {
17
+ return 'pages';
18
+ }
19
+
20
+ public function component(): string
21
+ {
22
+ return 'item';
23
+ }
24
+
25
+ public function attributes(): ?array
26
+ {
27
+ $query = $this->query;
28
+ if (isset($this->pageTypes) && sizeof($this->pageTypes) > 0) {
29
+ $query['type'] = $this->pageTypes;
30
+ }
31
+
32
+ return array_merge(parent::attributes(), [
33
+ 'placeholder' => trans('panneau.forms.page_placeholder'),
34
+ 'itemLabelPath' => 'title.'.app()->getLocale(),
35
+ 'itemImagePath' => null,
36
+ 'requestQuery' => $query,
37
+ ]);
38
+ }
39
+
40
+ public function withQuery($query)
41
+ {
42
+ $this->query = $query;
43
+ return $this;
44
+ }
45
+
46
+ public function withTypes($types)
47
+ {
48
+ $this->pageTypes = is_array($types) ? $types : func_get_args();
49
+ return $this;
50
+ }
51
+ }
@@ -0,0 +1,34 @@
1
+ <?php
2
+
3
+ namespace App\Panneau\Fields;
4
+
5
+ use Panneau\Fields\Text;
6
+
7
+ class PageSlug extends Text
8
+ {
9
+ public function component(): string
10
+ {
11
+ return 'page-slug';
12
+ }
13
+
14
+ public function attributes(): ?array
15
+ {
16
+ $locale = app()->getLocale();
17
+ $locales = config('locale.locales');
18
+ $finalLocale = in_array($this->name, $locales) ? $this->name : $locale;
19
+
20
+ return array_merge(parent::attributes(), [
21
+ 'routes' => [
22
+ 'page' => url()->routeForReactRouter($finalLocale . '.page', [
23
+ 'withoutPatterns' => true,
24
+ ]),
25
+ 'page_with_parent' => url()->routeForReactRouter(
26
+ $finalLocale . '.page_with_parent',
27
+ [
28
+ 'withoutPatterns' => true,
29
+ ]
30
+ ),
31
+ ],
32
+ ]);
33
+ }
34
+ }
@@ -0,0 +1,18 @@
1
+ <?php
2
+
3
+ namespace App\Panneau\Fields;
4
+
5
+ use Panneau\Support\LocalizedField;
6
+
7
+ class PageSlugLocalized extends LocalizedField
8
+ {
9
+ public function component(): string
10
+ {
11
+ return 'page-slug-localized';
12
+ }
13
+
14
+ public function field($locale)
15
+ {
16
+ return new PageSlug($locale);
17
+ }
18
+ }
@@ -0,0 +1,41 @@
1
+ <?php
2
+
3
+ namespace App\Panneau\Http\Controllers;
4
+
5
+ use App\Http\Controllers\Controller;
6
+ use App\Http\Resources\UserResource;
7
+ use App\Panneau\Http\Requests\AccountUpdateRequest;
8
+ use Folklore\Contracts\Repositories\Users as UsersRepository;
9
+
10
+ class AccountController extends Controller
11
+ {
12
+ protected $users;
13
+
14
+ public function __construct(UsersRepository $users)
15
+ {
16
+ $this->users = $users;
17
+ }
18
+
19
+ /**
20
+ * Show the account
21
+ *
22
+ * @return \Illuminate\Contracts\Support\Renderable
23
+ */
24
+ public function index()
25
+ {
26
+ return view('panneau::app');
27
+ }
28
+
29
+ /**
30
+ * Update the account
31
+ *
32
+ * @return \Illuminate\Contracts\Support\Renderable
33
+ */
34
+ public function update(AccountUpdateRequest $request)
35
+ {
36
+ $data = $request->all();
37
+ $user = $request->user();
38
+ $user = $this->users->update($user->id(), $data);
39
+ return new UserResource($user);
40
+ }
41
+ }
@@ -0,0 +1,19 @@
1
+ <?php
2
+
3
+ namespace App\Panneau\Http\Controllers;
4
+
5
+ use Illuminate\Support\Str;
6
+ use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
7
+ use Illuminate\Foundation\Bus\DispatchesJobs;
8
+ use Illuminate\Foundation\Validation\ValidatesRequests;
9
+ use Illuminate\Routing\Controller as BaseController;
10
+
11
+ class Controller extends BaseController
12
+ {
13
+ use AuthorizesRequests, DispatchesJobs, ValidatesRequests;
14
+
15
+ protected function requestIsJson($request)
16
+ {
17
+ return $request->wantsJson() || Str::endsWith($request->path(), '.json');
18
+ }
19
+ }
@@ -0,0 +1,16 @@
1
+ <?php
2
+
3
+ namespace App\Panneau\Http\Controllers;
4
+
5
+ class HomeController extends Controller
6
+ {
7
+ /**
8
+ * Show the home
9
+ *
10
+ * @return \Illuminate\Contracts\Support\Renderable
11
+ */
12
+ public function index()
13
+ {
14
+ return view('panneau::app');
15
+ }
16
+ }
@@ -0,0 +1,24 @@
1
+ <?php
2
+
3
+ namespace App\Panneau\Http\Controllers;
4
+
5
+ use Illuminate\Http\Request;
6
+ use Panneau\Contracts\Resource;
7
+ use Panneau\Http\Controllers\ResourceController;
8
+
9
+ class PagesController extends ResourceController
10
+ {
11
+ protected $defaultPageCount = 25;
12
+
13
+ protected function getResourceFromRequest(Request $request)
14
+ {
15
+ return app('panneau')->resource('pages');
16
+ }
17
+
18
+ protected function getIndexQueryFromRequest(Request $request, Resource $resource)
19
+ {
20
+ $query = parent::getIndexQueryFromRequest($request, $resource);
21
+
22
+ return $query;
23
+ }
24
+ }
@@ -0,0 +1,27 @@
1
+ <?php
2
+
3
+ namespace App\Panneau\Http\Controllers;
4
+
5
+ use App\Panneau\Http\Requests\UploadRequest;
6
+ use Folklore\Contracts\Repositories\Medias as MediasRepository;
7
+ use Folklore\Http\Resources\Medias\MediaResource;
8
+
9
+ class UploadController extends Controller
10
+ {
11
+ public function __construct(MediasRepository $medias)
12
+ {
13
+ $this->medias = $medias;
14
+ }
15
+
16
+ /**
17
+ * Show the account
18
+ *
19
+ * @return \Illuminate\Contracts\Support\Renderable
20
+ */
21
+ public function upload(UploadRequest $request)
22
+ {
23
+ $file = $request->file('file');
24
+ $media = $this->medias->createFromFile($file);
25
+ return new MediaResource($media);
26
+ }
27
+ }
@@ -0,0 +1,32 @@
1
+ <?php
2
+
3
+ namespace App\Panneau\Http\Controllers;
4
+
5
+ use Illuminate\Http\Request;
6
+ use Panneau\Http\Controllers\ResourceController;
7
+ use Panneau\Contracts\Resource;
8
+
9
+ class UsersController extends ResourceController
10
+ {
11
+ protected $defaultPageCount = 100;
12
+
13
+ protected function getResourceFromRequest(Request $request)
14
+ {
15
+ return app('panneau')->resource('users');
16
+ }
17
+
18
+ protected function getIndexQueryFromRequest(Request $request, Resource $resource)
19
+ {
20
+ $query = parent::getIndexQueryFromRequest($request, $resource);
21
+
22
+ if (!isset($query['order'])) {
23
+ $query['order'] = 'created_at';
24
+ }
25
+
26
+ if (!isset($query['role'])) {
27
+ $query['role'] = 'admin';
28
+ }
29
+
30
+ return $query;
31
+ }
32
+ }
@@ -0,0 +1,29 @@
1
+ <?php
2
+
3
+ namespace App\Panneau\Http\Requests;
4
+
5
+ use Illuminate\Foundation\Http\FormRequest;
6
+
7
+ class AccountUpdateRequest extends FormRequest
8
+ {
9
+ /**
10
+ * Determine if the user is authorized to make this request.
11
+ *
12
+ * @return bool
13
+ */
14
+ public function authorize()
15
+ {
16
+ $user = $this->user();
17
+ return !is_null($user);
18
+ }
19
+
20
+ /**
21
+ * Get the validation rules that apply to the request.
22
+ *
23
+ * @return array
24
+ */
25
+ public function rules()
26
+ {
27
+ return [];
28
+ }
29
+ }