2018-12-17 22:03:36 +03:00
|
|
|
import Bottle from 'bottlejs';
|
|
|
|
import { withRouter } from 'react-router-dom';
|
|
|
|
import { connect } from 'react-redux';
|
2018-12-18 00:18:47 +03:00
|
|
|
import { assoc, pick } from 'ramda';
|
|
|
|
import csvjson from 'csvjson';
|
|
|
|
import axios from 'axios';
|
2018-12-17 22:03:36 +03:00
|
|
|
import App from '../App';
|
|
|
|
import ScrollToTop from '../common/ScrollToTop';
|
|
|
|
import MainHeader from '../common/MainHeader';
|
2018-12-17 22:24:31 +03:00
|
|
|
import { resetSelectedServer, selectServer } from '../servers/reducers/selectedServer';
|
2018-12-17 22:03:36 +03:00
|
|
|
import Home from '../common/Home';
|
2018-12-17 22:24:31 +03:00
|
|
|
import MenuLayout from '../common/MenuLayout';
|
2018-12-18 00:18:47 +03:00
|
|
|
import { createServer, createServers, deleteServer, listServers } from '../servers/reducers/server';
|
2018-12-17 22:24:31 +03:00
|
|
|
import CreateServer from '../servers/CreateServer';
|
2018-12-18 00:18:47 +03:00
|
|
|
import ServersDropdown from '../servers/ServersDropdown';
|
|
|
|
import TagsList from '../tags/TagsList';
|
2018-12-18 01:11:55 +03:00
|
|
|
import { filterTags, forceListTags, listTags } from '../tags/reducers/tagsList';
|
2018-12-18 00:18:47 +03:00
|
|
|
import ShortUrls from '../short-urls/ShortUrls';
|
|
|
|
import SearchBar from '../short-urls/SearchBar';
|
|
|
|
import { listShortUrls } from '../short-urls/reducers/shortUrlsList';
|
|
|
|
import ShortUrlsList from '../short-urls/ShortUrlsList';
|
|
|
|
import { resetShortUrlParams } from '../short-urls/reducers/shortUrlsListParams';
|
|
|
|
import { ColorGenerator } from '../utils/ColorGenerator';
|
|
|
|
import { Storage } from '../utils/Storage';
|
|
|
|
import ShortUrlsRow from '../short-urls/helpers/ShortUrlsRow';
|
|
|
|
import ShortUrlsRowMenu from '../short-urls/helpers/ShortUrlsRowMenu';
|
2018-12-18 12:14:25 +03:00
|
|
|
import ShlinkApiClient from '../api/ShlinkApiClient';
|
2018-12-18 00:18:47 +03:00
|
|
|
import DeleteServerModal from '../servers/DeleteServerModal';
|
|
|
|
import DeleteServerButton from '../servers/DeleteServerButton';
|
|
|
|
import AsideMenu from '../common/AsideMenu';
|
|
|
|
import ImportServersBtn from '../servers/helpers/ImportServersBtn';
|
|
|
|
import { ServersImporter } from '../servers/services/ServersImporter';
|
|
|
|
import { ServersExporter } from '../servers/services/ServersExporter';
|
|
|
|
import { ServersService } from '../servers/services/ServersService';
|
2018-12-18 01:11:55 +03:00
|
|
|
import CreateShortUrl from '../short-urls/CreateShortUrl';
|
|
|
|
import { createShortUrl, resetCreateShortUrl } from '../short-urls/reducers/shortUrlCreation';
|
|
|
|
import TagsSelector from '../tags/helpers/TagsSelector';
|
|
|
|
import DeleteShortUrlModal from '../short-urls/helpers/DeleteShortUrlModal';
|
|
|
|
import { deleteShortUrl, resetDeleteShortUrl, shortUrlDeleted } from '../short-urls/reducers/shortUrlDeletion';
|
|
|
|
import EditTagsModal from '../short-urls/helpers/EditTagsModal';
|
|
|
|
import { editShortUrlTags, resetShortUrlsTags, shortUrlTagsEdited } from '../short-urls/reducers/shortUrlTags';
|
2018-12-18 12:14:25 +03:00
|
|
|
import buildShlinkApiClient from '../api/ShlinkApiClientBuilder';
|
2018-12-18 13:28:15 +03:00
|
|
|
import TagCard from '../tags/TagCard';
|
|
|
|
import DeleteTagConfirmModal from '../tags/helpers/DeleteTagConfirmModal';
|
|
|
|
import { deleteTag, tagDeleted } from '../tags/reducers/tagDelete';
|
|
|
|
import EditTagModal from '../tags/helpers/EditTagModal';
|
|
|
|
import { editTag, tagEdited } from '../tags/reducers/tagEdit';
|
2018-12-18 16:32:02 +03:00
|
|
|
import provideVisitsServices from '../visits/container/provideServices';
|
2018-12-17 22:03:36 +03:00
|
|
|
|
|
|
|
const bottle = new Bottle();
|
2018-12-18 06:34:37 +03:00
|
|
|
const { container } = bottle;
|
|
|
|
|
2018-12-18 12:14:25 +03:00
|
|
|
const mapActionService = (map, actionName) => ({
|
|
|
|
...map,
|
2018-12-18 06:34:37 +03:00
|
|
|
|
2018-12-18 12:14:25 +03:00
|
|
|
// Wrap actual action service in a function so that it is lazily created the first time it is called
|
|
|
|
[actionName]: (...args) => container[actionName](...args),
|
|
|
|
});
|
2018-12-18 06:34:37 +03:00
|
|
|
const connectDecorator = (propsFromState, actionServiceNames) =>
|
|
|
|
connect(
|
|
|
|
pick(propsFromState),
|
|
|
|
Array.isArray(actionServiceNames) ? actionServiceNames.reduce(mapActionService, {}) : actionServiceNames
|
|
|
|
);
|
2018-12-17 22:03:36 +03:00
|
|
|
|
2018-12-18 00:18:47 +03:00
|
|
|
bottle.constant('ScrollToTop', ScrollToTop);
|
|
|
|
bottle.decorator('ScrollToTop', withRouter);
|
|
|
|
|
|
|
|
bottle.serviceFactory('MainHeader', MainHeader, 'ServersDropdown');
|
|
|
|
bottle.decorator('MainHeader', withRouter);
|
|
|
|
|
|
|
|
bottle.serviceFactory('Home', () => Home);
|
2018-12-18 06:34:37 +03:00
|
|
|
bottle.decorator('Home', connectDecorator([ 'servers' ], { resetSelectedServer }));
|
2018-12-18 00:18:47 +03:00
|
|
|
|
2018-12-18 16:32:02 +03:00
|
|
|
bottle.serviceFactory(
|
|
|
|
'MenuLayout',
|
|
|
|
MenuLayout,
|
|
|
|
'TagsList',
|
|
|
|
'ShortUrls',
|
|
|
|
'AsideMenu',
|
|
|
|
'CreateShortUrl',
|
|
|
|
'ShortUrlVisits'
|
|
|
|
);
|
2018-12-18 06:34:37 +03:00
|
|
|
bottle.decorator('MenuLayout', connectDecorator([ 'selectedServer', 'shortUrlsListParams' ], { selectServer }));
|
|
|
|
bottle.decorator('MenuLayout', withRouter);
|
2018-12-18 00:18:47 +03:00
|
|
|
|
|
|
|
bottle.serviceFactory('CreateServer', CreateServer, 'ImportServersBtn');
|
2018-12-18 06:34:37 +03:00
|
|
|
bottle.decorator('CreateServer', connectDecorator([ 'selectedServer' ], { createServer, resetSelectedServer }));
|
2018-12-18 00:18:47 +03:00
|
|
|
|
2018-12-17 22:24:31 +03:00
|
|
|
bottle.serviceFactory('App', App, 'MainHeader', 'Home', 'MenuLayout', 'CreateServer');
|
2018-12-17 22:03:36 +03:00
|
|
|
|
2018-12-18 00:18:47 +03:00
|
|
|
bottle.serviceFactory('ServersDropdown', ServersDropdown, 'ServersExporter');
|
2018-12-18 06:34:37 +03:00
|
|
|
bottle.decorator('ServersDropdown', connectDecorator([ 'servers', 'selectedServer' ], { listServers, selectServer }));
|
2018-12-18 00:18:47 +03:00
|
|
|
|
2018-12-18 13:28:15 +03:00
|
|
|
bottle.serviceFactory('TagsList', TagsList, 'TagCard');
|
2018-12-18 06:34:37 +03:00
|
|
|
bottle.decorator('TagsList', connectDecorator([ 'tagsList' ], { forceListTags, filterTags }));
|
2018-12-18 00:18:47 +03:00
|
|
|
|
|
|
|
bottle.serviceFactory('ShortUrls', ShortUrls, 'SearchBar', 'ShortUrlsList');
|
|
|
|
bottle.decorator('ShortUrls', connect(
|
|
|
|
(state) => assoc('shortUrlsList', state.shortUrlsList.shortUrls, state.shortUrlsList)
|
|
|
|
));
|
|
|
|
|
2018-12-18 13:28:15 +03:00
|
|
|
bottle.serviceFactory('SearchBar', SearchBar, 'ColorGenerator');
|
2018-12-18 06:34:37 +03:00
|
|
|
bottle.decorator('SearchBar', connectDecorator([ 'shortUrlsListParams' ], { listShortUrls }));
|
2018-12-18 00:18:47 +03:00
|
|
|
|
|
|
|
bottle.serviceFactory('ShortUrlsList', ShortUrlsList, 'ShortUrlsRow');
|
2018-12-18 06:34:37 +03:00
|
|
|
bottle.decorator('ShortUrlsList', connectDecorator(
|
|
|
|
[ 'selectedServer', 'shortUrlsListParams' ],
|
2018-12-18 00:18:47 +03:00
|
|
|
{ listShortUrls, resetShortUrlParams }
|
|
|
|
));
|
|
|
|
|
|
|
|
bottle.constant('localStorage', global.localStorage);
|
|
|
|
bottle.service('Storage', Storage, 'localStorage');
|
|
|
|
bottle.service('ColorGenerator', ColorGenerator, 'Storage');
|
|
|
|
|
2018-12-18 13:28:15 +03:00
|
|
|
bottle.serviceFactory('ShortUrlsRow', ShortUrlsRow, 'ShortUrlsRowMenu', 'ColorGenerator');
|
2018-12-18 00:18:47 +03:00
|
|
|
|
2018-12-18 01:11:55 +03:00
|
|
|
bottle.serviceFactory('ShortUrlsRowMenu', ShortUrlsRowMenu, 'DeleteShortUrlModal', 'EditTagsModal');
|
2018-12-18 00:18:47 +03:00
|
|
|
|
|
|
|
bottle.constant('axios', axios);
|
|
|
|
bottle.service('ShlinkApiClient', ShlinkApiClient, 'axios');
|
|
|
|
|
|
|
|
bottle.serviceFactory('DeleteServerModal', () => DeleteServerModal);
|
2018-12-18 06:34:37 +03:00
|
|
|
bottle.decorator('DeleteServerModal', withRouter);
|
|
|
|
bottle.decorator('DeleteServerModal', connect(null, { deleteServer }));
|
2018-12-18 00:18:47 +03:00
|
|
|
|
|
|
|
bottle.serviceFactory('DeleteServerButton', DeleteServerButton, 'DeleteServerModal');
|
|
|
|
bottle.serviceFactory('AsideMenu', AsideMenu, 'DeleteServerButton');
|
|
|
|
|
|
|
|
bottle.serviceFactory('ImportServersBtn', ImportServersBtn, 'ServersImporter');
|
|
|
|
bottle.decorator('ImportServersBtn', connect(null, { createServers }));
|
|
|
|
|
|
|
|
bottle.constant('csvjson', csvjson);
|
|
|
|
bottle.constant('window', global.window);
|
|
|
|
bottle.service('ServersImporter', ServersImporter, 'csvjson');
|
|
|
|
bottle.service('ServersService', ServersService, 'Storage');
|
|
|
|
bottle.service('ServersExporter', ServersExporter, 'ServersService', 'window', 'csvjson');
|
|
|
|
|
2018-12-18 01:11:55 +03:00
|
|
|
bottle.serviceFactory('CreateShortUrl', CreateShortUrl, 'TagsSelector');
|
2018-12-18 06:34:37 +03:00
|
|
|
bottle.decorator('CreateShortUrl', connectDecorator([ 'shortUrlCreationResult' ], {
|
2018-12-18 01:11:55 +03:00
|
|
|
createShortUrl,
|
|
|
|
resetCreateShortUrl,
|
|
|
|
}));
|
|
|
|
|
|
|
|
bottle.serviceFactory('TagsSelector', TagsSelector, 'ColorGenerator');
|
2018-12-18 06:34:37 +03:00
|
|
|
bottle.decorator('TagsSelector', connectDecorator([ 'tagsList' ], { listTags }));
|
2018-12-18 01:11:55 +03:00
|
|
|
|
|
|
|
bottle.serviceFactory('DeleteShortUrlModal', () => DeleteShortUrlModal);
|
2018-12-18 06:34:37 +03:00
|
|
|
bottle.decorator('DeleteShortUrlModal', connectDecorator(
|
|
|
|
[ 'shortUrlDeletion' ],
|
2018-12-18 01:11:55 +03:00
|
|
|
{ deleteShortUrl, resetDeleteShortUrl, shortUrlDeleted }
|
|
|
|
));
|
2018-12-18 06:54:32 +03:00
|
|
|
|
2018-12-18 01:11:55 +03:00
|
|
|
bottle.serviceFactory('EditTagsModal', EditTagsModal, 'TagsSelector');
|
2018-12-18 06:34:37 +03:00
|
|
|
bottle.decorator('EditTagsModal', connectDecorator(
|
|
|
|
[ 'shortUrlTags' ],
|
2018-12-18 06:54:32 +03:00
|
|
|
[ 'editShortUrlTags', 'resetShortUrlsTags', 'shortUrlTagsEdited' ]
|
2018-12-18 01:11:55 +03:00
|
|
|
));
|
|
|
|
|
2018-12-18 12:14:25 +03:00
|
|
|
bottle.serviceFactory('editShortUrlTags', editShortUrlTags, 'buildShlinkApiClient');
|
2018-12-18 07:03:38 +03:00
|
|
|
bottle.serviceFactory('resetShortUrlsTags', () => resetShortUrlsTags);
|
|
|
|
bottle.serviceFactory('shortUrlTagsEdited', () => shortUrlTagsEdited);
|
|
|
|
|
2018-12-18 12:14:25 +03:00
|
|
|
bottle.serviceFactory('buildShlinkApiClient', buildShlinkApiClient, 'axios');
|
|
|
|
|
2018-12-18 13:28:15 +03:00
|
|
|
bottle.serviceFactory('TagCard', TagCard, 'DeleteTagConfirmModal', 'EditTagModal', 'ColorGenerator');
|
|
|
|
|
|
|
|
bottle.serviceFactory('DeleteTagConfirmModal', () => DeleteTagConfirmModal);
|
|
|
|
bottle.decorator('DeleteTagConfirmModal', connectDecorator([ 'tagDelete' ], { deleteTag, tagDeleted }));
|
|
|
|
|
|
|
|
bottle.serviceFactory('EditTagModal', EditTagModal, 'ColorGenerator');
|
|
|
|
bottle.decorator('EditTagModal', connectDecorator([ 'tagEdit' ], { editTag, tagEdited }));
|
|
|
|
|
2018-12-18 16:32:02 +03:00
|
|
|
provideVisitsServices(bottle, connectDecorator);
|
|
|
|
|
2018-12-18 06:34:37 +03:00
|
|
|
export default container;
|