|
1
|
|
|
import Bottle from 'bottlejs'; |
|
2
|
|
|
import { withRouter } from 'react-router-dom'; |
|
3
|
|
|
import { connect } from 'react-redux'; |
|
4
|
|
|
import { assoc, pick } from 'ramda'; |
|
5
|
|
|
import csvjson from 'csvjson'; |
|
6
|
|
|
import axios from 'axios'; |
|
7
|
|
|
import App from '../App'; |
|
8
|
|
|
import ScrollToTop from '../common/ScrollToTop'; |
|
9
|
|
|
import MainHeader from '../common/MainHeader'; |
|
10
|
|
|
import { resetSelectedServer, selectServer } from '../servers/reducers/selectedServer'; |
|
11
|
|
|
import Home from '../common/Home'; |
|
12
|
|
|
import MenuLayout from '../common/MenuLayout'; |
|
13
|
|
|
import { createServer, createServers, deleteServer, listServers } from '../servers/reducers/server'; |
|
14
|
|
|
import CreateServer from '../servers/CreateServer'; |
|
15
|
|
|
import ServersDropdown from '../servers/ServersDropdown'; |
|
16
|
|
|
import TagsList from '../tags/TagsList'; |
|
17
|
|
|
import { filterTags, forceListTags, listTags } from '../tags/reducers/tagsList'; |
|
18
|
|
|
import ShortUrls from '../short-urls/ShortUrls'; |
|
19
|
|
|
import SearchBar from '../short-urls/SearchBar'; |
|
20
|
|
|
import { listShortUrls } from '../short-urls/reducers/shortUrlsList'; |
|
21
|
|
|
import ShortUrlsList from '../short-urls/ShortUrlsList'; |
|
22
|
|
|
import { resetShortUrlParams } from '../short-urls/reducers/shortUrlsListParams'; |
|
23
|
|
|
import Tag from '../tags/helpers/Tag'; |
|
24
|
|
|
import { ColorGenerator } from '../utils/ColorGenerator'; |
|
25
|
|
|
import { Storage } from '../utils/Storage'; |
|
26
|
|
|
import ShortUrlsRow from '../short-urls/helpers/ShortUrlsRow'; |
|
27
|
|
|
import ShortUrlsRowMenu from '../short-urls/helpers/ShortUrlsRowMenu'; |
|
28
|
|
|
import { ShlinkApiClient } from '../api/ShlinkApiClient'; |
|
29
|
|
|
import DeleteServerModal from '../servers/DeleteServerModal'; |
|
30
|
|
|
import DeleteServerButton from '../servers/DeleteServerButton'; |
|
31
|
|
|
import AsideMenu from '../common/AsideMenu'; |
|
32
|
|
|
import ImportServersBtn from '../servers/helpers/ImportServersBtn'; |
|
33
|
|
|
import { ServersImporter } from '../servers/services/ServersImporter'; |
|
34
|
|
|
import { ServersExporter } from '../servers/services/ServersExporter'; |
|
35
|
|
|
import { ServersService } from '../servers/services/ServersService'; |
|
36
|
|
|
import CreateShortUrl from '../short-urls/CreateShortUrl'; |
|
37
|
|
|
import { createShortUrl, resetCreateShortUrl } from '../short-urls/reducers/shortUrlCreation'; |
|
38
|
|
|
import TagsSelector from '../tags/helpers/TagsSelector'; |
|
39
|
|
|
import DeleteShortUrlModal from '../short-urls/helpers/DeleteShortUrlModal'; |
|
40
|
|
|
import { deleteShortUrl, resetDeleteShortUrl, shortUrlDeleted } from '../short-urls/reducers/shortUrlDeletion'; |
|
41
|
|
|
import EditTagsModal from '../short-urls/helpers/EditTagsModal'; |
|
42
|
4 |
|
import { editShortUrlTags, resetShortUrlsTags, shortUrlTagsEdited } from '../short-urls/reducers/shortUrlTags'; |
|
43
|
|
|
|
|
44
|
|
|
const bottle = new Bottle(); |
|
45
|
|
|
const { container } = bottle; |
|
46
|
|
|
|
|
47
|
|
|
const mapActionService = (map, actionName) => { |
|
48
|
|
|
// Wrap actual action service in a function so that it is lazily created the first time it is called |
|
49
|
|
|
map[actionName] = (...args) => container[actionName](...args); |
|
50
|
|
|
|
|
51
|
|
|
return map; |
|
52
|
|
|
}; |
|
53
|
|
|
const connectDecorator = (propsFromState, actionServiceNames) => |
|
54
|
|
|
connect( |
|
55
|
|
|
pick(propsFromState), |
|
56
|
|
|
Array.isArray(actionServiceNames) ? actionServiceNames.reduce(mapActionService, {}) : actionServiceNames |
|
57
|
|
|
); |
|
58
|
|
|
|
|
59
|
|
|
bottle.constant('ScrollToTop', ScrollToTop); |
|
60
|
|
|
bottle.decorator('ScrollToTop', withRouter); |
|
61
|
|
|
|
|
62
|
|
|
bottle.serviceFactory('MainHeader', MainHeader, 'ServersDropdown'); |
|
63
|
|
|
bottle.decorator('MainHeader', withRouter); |
|
64
|
|
|
|
|
65
|
|
|
bottle.serviceFactory('Home', () => Home); |
|
66
|
|
|
bottle.decorator('Home', connectDecorator([ 'servers' ], { resetSelectedServer })); |
|
67
|
|
|
|
|
68
|
|
|
bottle.serviceFactory('MenuLayout', MenuLayout, 'TagsList', 'ShortUrls', 'AsideMenu', 'CreateShortUrl'); |
|
69
|
|
|
bottle.decorator('MenuLayout', connectDecorator([ 'selectedServer', 'shortUrlsListParams' ], { selectServer })); |
|
70
|
|
|
bottle.decorator('MenuLayout', withRouter); |
|
71
|
|
|
|
|
72
|
|
|
bottle.serviceFactory('CreateServer', CreateServer, 'ImportServersBtn'); |
|
73
|
|
|
bottle.decorator('CreateServer', connectDecorator([ 'selectedServer' ], { createServer, resetSelectedServer })); |
|
74
|
|
|
|
|
75
|
|
|
bottle.serviceFactory('App', App, 'MainHeader', 'Home', 'MenuLayout', 'CreateServer'); |
|
76
|
|
|
|
|
77
|
|
|
bottle.serviceFactory('ServersDropdown', ServersDropdown, 'ServersExporter'); |
|
78
|
|
|
bottle.decorator('ServersDropdown', connectDecorator([ 'servers', 'selectedServer' ], { listServers, selectServer })); |
|
79
|
|
|
|
|
80
|
|
|
bottle.serviceFactory('TagsList', () => TagsList); |
|
81
|
|
|
bottle.decorator('TagsList', connectDecorator([ 'tagsList' ], { forceListTags, filterTags })); |
|
82
|
|
|
|
|
83
|
|
|
bottle.serviceFactory('ShortUrls', ShortUrls, 'SearchBar', 'ShortUrlsList'); |
|
84
|
|
|
bottle.decorator('ShortUrls', connect( |
|
85
|
|
|
(state) => assoc('shortUrlsList', state.shortUrlsList.shortUrls, state.shortUrlsList) |
|
86
|
|
|
)); |
|
87
|
|
|
|
|
88
|
|
|
bottle.serviceFactory('SearchBar', SearchBar, 'Tag'); |
|
89
|
|
|
bottle.decorator('SearchBar', connectDecorator([ 'shortUrlsListParams' ], { listShortUrls })); |
|
90
|
|
|
|
|
91
|
|
|
bottle.serviceFactory('ShortUrlsList', ShortUrlsList, 'ShortUrlsRow'); |
|
92
|
|
|
bottle.decorator('ShortUrlsList', connectDecorator( |
|
93
|
|
|
[ 'selectedServer', 'shortUrlsListParams' ], |
|
94
|
|
|
{ listShortUrls, resetShortUrlParams } |
|
95
|
|
|
)); |
|
96
|
|
|
|
|
97
|
|
|
bottle.serviceFactory('Tag', Tag, 'ColorGenerator'); |
|
98
|
|
|
|
|
99
|
|
|
bottle.constant('localStorage', global.localStorage); |
|
100
|
|
|
bottle.service('Storage', Storage, 'localStorage'); |
|
101
|
|
|
bottle.service('ColorGenerator', ColorGenerator, 'Storage'); |
|
102
|
|
|
|
|
103
|
|
|
bottle.serviceFactory('ShortUrlsRow', ShortUrlsRow, 'Tag', 'ShortUrlsRowMenu'); |
|
104
|
|
|
|
|
105
|
|
|
bottle.serviceFactory('ShortUrlsRowMenu', ShortUrlsRowMenu, 'DeleteShortUrlModal', 'EditTagsModal'); |
|
106
|
|
|
|
|
107
|
|
|
bottle.constant('axios', axios); |
|
108
|
|
|
bottle.service('ShlinkApiClient', ShlinkApiClient, 'axios'); |
|
109
|
|
|
|
|
110
|
|
|
bottle.serviceFactory('DeleteServerModal', () => DeleteServerModal); |
|
111
|
|
|
bottle.decorator('DeleteServerModal', withRouter); |
|
112
|
|
|
bottle.decorator('DeleteServerModal', connect(null, { deleteServer })); |
|
113
|
|
|
|
|
114
|
|
|
bottle.serviceFactory('DeleteServerButton', DeleteServerButton, 'DeleteServerModal'); |
|
115
|
|
|
bottle.serviceFactory('AsideMenu', AsideMenu, 'DeleteServerButton'); |
|
116
|
|
|
|
|
117
|
|
|
bottle.serviceFactory('ImportServersBtn', ImportServersBtn, 'ServersImporter'); |
|
118
|
|
|
bottle.decorator('ImportServersBtn', connect(null, { createServers })); |
|
119
|
|
|
|
|
120
|
|
|
bottle.constant('csvjson', csvjson); |
|
121
|
|
|
bottle.constant('window', global.window); |
|
122
|
|
|
bottle.service('ServersImporter', ServersImporter, 'csvjson'); |
|
123
|
|
|
bottle.service('ServersService', ServersService, 'Storage'); |
|
124
|
|
|
bottle.service('ServersExporter', ServersExporter, 'ServersService', 'window', 'csvjson'); |
|
125
|
|
|
|
|
126
|
|
|
bottle.serviceFactory('CreateShortUrl', CreateShortUrl, 'TagsSelector'); |
|
127
|
|
|
bottle.decorator('CreateShortUrl', connectDecorator([ 'shortUrlCreationResult' ], { |
|
128
|
|
|
createShortUrl, |
|
129
|
|
|
resetCreateShortUrl, |
|
130
|
|
|
})); |
|
131
|
|
|
|
|
132
|
|
|
bottle.serviceFactory('TagsSelector', TagsSelector, 'ColorGenerator'); |
|
133
|
|
|
bottle.decorator('TagsSelector', connectDecorator([ 'tagsList' ], { listTags })); |
|
134
|
|
|
|
|
135
|
|
|
bottle.serviceFactory('DeleteShortUrlModal', () => DeleteShortUrlModal); |
|
136
|
|
|
bottle.decorator('DeleteShortUrlModal', connectDecorator( |
|
137
|
|
|
[ 'shortUrlDeletion' ], |
|
138
|
|
|
{ deleteShortUrl, resetDeleteShortUrl, shortUrlDeleted } |
|
139
|
|
|
)); |
|
140
|
|
|
|
|
141
|
|
|
bottle.serviceFactory('EditTagsModal', EditTagsModal, 'TagsSelector'); |
|
142
|
|
|
bottle.decorator('EditTagsModal', connectDecorator( |
|
143
|
|
|
[ 'shortUrlTags' ], |
|
144
|
|
|
[ 'editShortUrlTags', 'resetShortUrlsTags', 'shortUrlTagsEdited' ] |
|
145
|
|
|
)); |
|
146
|
|
|
|
|
147
|
|
|
bottle.serviceFactory('editShortUrlTags', editShortUrlTags, 'ShlinkApiClient'); |
|
148
|
|
|
bottle.serviceFactory('resetShortUrlsTags', () => resetShortUrlsTags); |
|
149
|
|
|
bottle.serviceFactory('shortUrlTagsEdited', () => shortUrlTagsEdited); |
|
150
|
|
|
|
|
151
|
|
|
export default container; |
|
152
|
|
|
|