talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 1 | /*! |
| 2 | * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express |
| 13 | * or implied. See the License for the specific language governing |
| 14 | * permissions and limitations under the License. |
| 15 | */ |
| 16 | import {Factory} from 'rosie'; |
| 17 | import randomstring from 'randomstring'; |
| 18 | import VersionFactory from './VersionFactory.js'; |
| 19 | |
| 20 | export const InitializedItemPermissionFactory = new Factory() |
| 21 | .attrs({ |
| 22 | 'isCertified': false, |
| 23 | 'inMerge': false, |
| 24 | 'isCollaborator': true |
| 25 | }); |
| 26 | |
| 27 | export const ItemPermissionFactory = new Factory() |
| 28 | .extend(InitializedItemPermissionFactory) |
| 29 | .attrs({ |
| 30 | 'isDirty': false, |
| 31 | 'isOutOfSync': false, |
svishnev | 091edfd | 2018-03-19 12:15:19 +0200 | [diff] [blame^] | 32 | 'isArchived': false, |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 33 | 'isUpToDate': true |
| 34 | }); |
| 35 | |
| 36 | |
| 37 | export const CurrentScreenPropsFactory = new Factory() |
| 38 | .option('versionId', () => randomstring.generate()) |
| 39 | .option('versionBaseId', () => randomstring.generate()) |
| 40 | .attrs({ |
| 41 | softwareProductId: () => randomstring.generate(), |
| 42 | licenseModelId: () => randomstring.generate(), |
| 43 | isReadOnlyMode: false |
| 44 | }) |
| 45 | .attr('version', [ |
| 46 | 'versionId', 'versionBaseId' |
| 47 | ], (id, baseId) => |
| 48 | VersionFactory.build({id, baseId}) |
| 49 | ); |
| 50 | |
| 51 | |
| 52 | Factory.define('InitializedCurrentScreenFactory') |
| 53 | .option('isCertified', false) |
| 54 | .option('inMerge', false) |
| 55 | .option('isCollaborator', true) |
svishnev | 091edfd | 2018-03-19 12:15:19 +0200 | [diff] [blame^] | 56 | .option('isArchived', false) |
| 57 | .option('isReadOnlyMode', ['isCertified', 'inMerge', 'isCollaborator', 'isArchived'], (isCertified, inMerge, isCollaborator, isArchived) => |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 58 | isCertified || inMerge || !isCollaborator |
| 59 | ) |
| 60 | .attr('itemPermission', ['isCertified', 'inMerge', 'isCollaborator'], (isCertified, inMerge, isCollaborator) => |
| 61 | InitializedItemPermissionFactory.build({isCollaborator, isCertified, inMerge}) |
| 62 | ) |
| 63 | .attr('props', ['isReadOnlyMode'], (isReadOnlyMode) => { |
| 64 | return {isReadOnlyMode}; |
| 65 | }); |
| 66 | export const InitializedCurrentScreenFactory = new Factory().extend('InitializedCurrentScreenFactory'); |
| 67 | |
| 68 | |
| 69 | Factory.define('CurrentScreenFactory') |
| 70 | .extend('InitializedCurrentScreenFactory') |
| 71 | .option('isDirty', false) |
| 72 | .option('isOutOfSync', false) |
| 73 | .option('isUpToDate', true) |
| 74 | .option('version', ['isCertified'], (isCertified) => VersionFactory.build({isCertified})) |
| 75 | .attr('itemPermission', [ |
svishnev | 091edfd | 2018-03-19 12:15:19 +0200 | [diff] [blame^] | 76 | 'isCertified', 'inMerge', 'isCollaborator', 'isDirty', 'isOutOfSync', 'isUpToDate', 'isArchived' |
| 77 | ], (isCertified, inMerge, isCollaborator, isDirty, isOutOfSync, isUpToDate, isArchived) => |
| 78 | ItemPermissionFactory.build({isCollaborator, isCertified, inMerge, isDirty, isOutOfSync, isUpToDate, isArchived}) |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 79 | ) |
| 80 | .attr('props', ['isReadOnlyMode', 'version'], (isReadOnlyMode, version) => { |
| 81 | return {isReadOnlyMode, version}; |
| 82 | }); |
| 83 | export default new Factory().extend('CurrentScreenFactory'); |
| 84 | |
| 85 | |
| 86 | export const CurrentScreenFactoryWithProps = new Factory() |
| 87 | .extend('CurrentScreenFactory') |
| 88 | .option('versionId') |
| 89 | .option('versionBaseId') |
| 90 | .option('version') |
| 91 | .attr('props', [ |
| 92 | 'isReadOnlyMode', 'versionId', 'versionBaseId', 'version' |
| 93 | ], (isReadOnlyMode, id, baseId, version) => { |
| 94 | let attrs = {isReadOnlyMode}; |
| 95 | let options = {}; |
| 96 | |
| 97 | if (version !== undefined) { attrs['version'] = version; } |
| 98 | if (id !== undefined) { options['versionId'] = id; } |
| 99 | if (baseId !== undefined) { options['versionBaseId'] = baseId; } |
| 100 | |
| 101 | return CurrentScreenPropsFactory.build(attrs, options); |
| 102 | }); |