| 
									
										
										
										
											2020-10-22 16:43:51 +02:00
										 |  |  | 'use strict'; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-11-15 19:10:23 +01:00
										 |  |  | const { pick, getOr } = require('lodash/fp'); | 
					
						
							| 
									
										
										
										
											2021-04-29 13:51:12 +02:00
										 |  |  | const { contentTypes: contentTypesUtils } = require('@strapi/utils'); | 
					
						
							| 
									
										
										
										
											2020-10-22 16:43:51 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | const dtoFields = [ | 
					
						
							|  |  |  |   'uid', | 
					
						
							|  |  |  |   'isDisplayed', | 
					
						
							|  |  |  |   'apiID', | 
					
						
							|  |  |  |   'kind', | 
					
						
							|  |  |  |   'category', | 
					
						
							|  |  |  |   'info', | 
					
						
							|  |  |  |   'options', | 
					
						
							| 
									
										
										
										
											2021-03-04 17:13:08 +01:00
										 |  |  |   'pluginOptions', | 
					
						
							| 
									
										
										
										
											2020-10-22 16:43:51 +02:00
										 |  |  |   'attributes', | 
					
						
							| 
									
										
										
										
											2021-03-08 11:02:01 +01:00
										 |  |  |   'pluginOptions', | 
					
						
							| 
									
										
										
										
											2020-10-22 16:43:51 +02:00
										 |  |  | ]; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-07-13 18:46:36 +02:00
										 |  |  | module.exports = () => ({ | 
					
						
							| 
									
										
										
										
											2020-10-22 16:43:51 +02:00
										 |  |  |   toContentManagerModel(contentType) { | 
					
						
							|  |  |  |     return { | 
					
						
							|  |  |  |       ...contentType, | 
					
						
							|  |  |  |       apiID: contentType.modelName, | 
					
						
							| 
									
										
										
										
											2021-02-10 14:29:54 +01:00
										 |  |  |       isDisplayed: isVisible(contentType), | 
					
						
							| 
									
										
										
										
											2020-10-22 16:43:51 +02:00
										 |  |  |       attributes: { | 
					
						
							|  |  |  |         id: { | 
					
						
							| 
									
										
										
										
											2021-06-30 22:52:12 +02:00
										 |  |  |           type: 'integer', | 
					
						
							| 
									
										
										
										
											2020-10-22 16:43:51 +02:00
										 |  |  |         }, | 
					
						
							|  |  |  |         ...formatAttributes(contentType), | 
					
						
							|  |  |  |       }, | 
					
						
							|  |  |  |     }; | 
					
						
							|  |  |  |   }, | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   toDto: pick(dtoFields), | 
					
						
							| 
									
										
										
										
											2021-07-13 18:46:36 +02:00
										 |  |  | }); | 
					
						
							| 
									
										
										
										
											2020-10-22 16:43:51 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-08-08 23:33:39 +02:00
										 |  |  | const formatAttributes = (contentType) => { | 
					
						
							| 
									
										
										
										
											2021-11-15 19:10:23 +01:00
										 |  |  |   const { getVisibleAttributes, getTimestamps } = contentTypesUtils; | 
					
						
							| 
									
										
										
										
											2020-10-22 16:43:51 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-03-12 14:34:04 +01:00
										 |  |  |   // only get attributes that can be seen in the auto generated Edit view or List view
 | 
					
						
							| 
									
										
										
										
											2021-11-15 19:10:23 +01:00
										 |  |  |   return getVisibleAttributes(contentType) | 
					
						
							|  |  |  |     .concat(getTimestamps(contentType)) | 
					
						
							|  |  |  |     .reduce((acc, key) => { | 
					
						
							|  |  |  |       const attribute = contentType.attributes[key]; | 
					
						
							| 
									
										
										
										
											2021-07-29 14:39:28 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-11-15 19:10:23 +01:00
										 |  |  |       // ignore morph until they are handled in the front
 | 
					
						
							|  |  |  |       if (attribute.type === 'relation' && attribute.relation.toLowerCase().includes('morph')) { | 
					
						
							|  |  |  |         return acc; | 
					
						
							|  |  |  |       } | 
					
						
							| 
									
										
										
										
											2021-07-29 14:39:28 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-11-15 19:10:23 +01:00
										 |  |  |       acc[key] = formatAttribute(key, attribute); | 
					
						
							|  |  |  |       return acc; | 
					
						
							|  |  |  |     }, {}); | 
					
						
							| 
									
										
										
										
											2020-10-22 16:43:51 +02:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-06-22 17:13:11 +02:00
										 |  |  | // FIXME: not needed
 | 
					
						
							| 
									
										
										
										
											2021-07-29 14:39:28 +02:00
										 |  |  | const formatAttribute = (key, attribute) => { | 
					
						
							| 
									
										
										
										
											2021-06-30 22:52:12 +02:00
										 |  |  |   if (attribute.type === 'relation') { | 
					
						
							|  |  |  |     return toRelation(attribute); | 
					
						
							| 
									
										
										
										
											2020-10-22 16:43:51 +02:00
										 |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-06-30 22:52:12 +02:00
										 |  |  |   return attribute; | 
					
						
							| 
									
										
										
										
											2020-10-22 16:43:51 +02:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-06-22 17:13:11 +02:00
										 |  |  | // FIXME: not needed
 | 
					
						
							| 
									
										
										
										
											2022-08-08 23:33:39 +02:00
										 |  |  | const toRelation = (attribute) => { | 
					
						
							| 
									
										
										
										
											2020-10-22 16:43:51 +02:00
										 |  |  |   return { | 
					
						
							|  |  |  |     ...attribute, | 
					
						
							|  |  |  |     type: 'relation', | 
					
						
							| 
									
										
										
										
											2021-06-30 22:52:12 +02:00
										 |  |  |     targetModel: attribute.target, | 
					
						
							|  |  |  |     relationType: attribute.relation, | 
					
						
							| 
									
										
										
										
											2020-10-22 16:43:51 +02:00
										 |  |  |   }; | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-08-08 23:33:39 +02:00
										 |  |  | const isVisible = (model) => getOr(true, 'pluginOptions.content-manager.visible', model) === true; |