Commit a577a639 authored by Viacheslav Pavlov's avatar Viacheslav Pavlov Committed by Matija Obreza
Browse files

Added cooperator module

parent cf2e5931
import Geography from '@gringlobal/client/model/gringlobal/Geography';
import Site from '@gringlobal/client/model/gringlobal/Site';
import SysLang from '@gringlobal/client/model/gringlobal/SysLang';
import WebCooperator from '@gringlobal/client/model/gringlobal/WebCooperator';
/**
* Cooperator
*
* GRIN-Global CE API
*/
class Cooperator {
public createdBy: number;
public createdDate: Date;
public modifiedBy: number;
public modifiedDate: Date;
public ownedBy: Cooperator;
public ownedDate: Date;
public addressLine1: string;
public addressLine2: string;
public addressLine3: string;
public categoryCode: string;
public city: string;
public currentCooperator: number;
public disciplineCode: string;
public email: string;
public fax: string;
public firstName: string;
public geography: Geography;
public id: number;
public job: string;
public lastName: string;
public note: string;
public organization: string;
public organizationAbbrev: string;
public organizationRegionCode: string;
public postalIndex: string;
public primaryPhone: string;
public secondaryAddressLine1: string;
public secondaryAddressLine2: string;
public secondaryAddressLine3: string;
public secondaryCity: string;
public secondaryEmail: string;
public secondaryGeography: Geography;
public secondaryOrganization: string;
public secondaryOrganizationAbbrev: string;
public secondaryPhone: string;
public secondaryPostalIndex: string;
public site: Site;
public statusCode: string;
public sysLang: SysLang;
public title: string;
public webCooperator: WebCooperator;
}
export default Cooperator;
import DateFilter from '@gringlobal/client/model/gringlobal/DateFilter';
import SiteFilter from '@gringlobal/client/model/gringlobal/SiteFilter';
import StringFilter from '@gringlobal/client/model/gringlobal/StringFilter';
/**
* CooperatorFilter
*
* GRIN-Global CE API
*/
class CooperatorFilter {
public NOT: CooperatorFilter;
public NULL: string[];
public NOTNULL: string[];
public createdBy: CooperatorFilter;
public createdDate: DateFilter;
public modifiedBy: CooperatorFilter;
public modifiedDate: DateFilter;
public ownedBy: CooperatorFilter;
public ownedDate: DateFilter;
public id: number[];
public addressLine1: StringFilter;
public addressLine2: StringFilter;
public addressLine3: StringFilter;
public categoryCode: StringFilter;
public city: StringFilter;
public current: boolean;
public disciplineCode: StringFilter;
public email: StringFilter;
public fax: StringFilter;
public firstName: StringFilter;
public job: StringFilter;
public lastName: StringFilter;
public note: StringFilter;
public organization: StringFilter;
public organizationAbbrev: StringFilter;
public organizationRegionCode: StringFilter;
public postalIndex: StringFilter;
public primaryPhone: StringFilter;
public secondaryAddressLine1: StringFilter;
public secondaryAddressLine2: StringFilter;
public secondaryAddressLine3: StringFilter;
public secondaryCity: StringFilter;
public secondaryEmail: StringFilter;
public secondaryOrganization: StringFilter;
public secondaryOrganizationAbbrev: StringFilter;
public secondaryPhone: StringFilter;
public secondaryPostalIndex: StringFilter;
public site: SiteFilter;
public statusCode: StringFilter;
public title: StringFilter;
}
export default CooperatorFilter;
/**
* DateFilter
*
* GRIN-Global CE API
*/
class DateFilter {
public ge: Date;
public gt: Date;
public le: Date;
public lt: Date;
public between: Date[];
}
export default DateFilter;
import Cooperator from '@gringlobal/client/model/gringlobal/Cooperator';
/**
* Geography
*
* GRIN-Global CE API
*/
class Geography {
public createdBy: number;
public createdDate: Date;
public modifiedBy: number;
public modifiedDate: Date;
public ownedBy: Cooperator;
public ownedDate: Date;
public adm1: string;
public adm1Abbrev: string;
public adm1TypeCode: string;
public adm2: string;
public adm2Abbrev: string;
public adm2TypeCode: string;
public adm3: string;
public adm3Abbrev: string;
public adm3TypeCode: string;
public adm4: string;
public adm4Abbrev: string;
public adm4TypeCode: string;
public changedDate: Date;
public countryCode: string;
public currentGeography: number;
public id: number;
public isValid: string;
public note: string;
}
export default Geography;
import Cooperator from '@gringlobal/client/model/gringlobal/Cooperator';
/**
* Site
*
* GRIN-Global CE API
*/
class Site {
public createdBy: number;
public createdDate: Date;
public modifiedBy: number;
public modifiedDate: Date;
public ownedBy: Cooperator;
public ownedDate: Date;
public faoInstituteNumber: string;
public id: number;
public isDistributionSite: string;
public isInternal: string;
public note: string;
public organizationAbbrev: string;
public providerIdentifier: string;
public siteLongName: string;
public siteShortName: string;
public typeCode: string;
}
export default Site;
import CooperatorFilter from '@gringlobal/client/model/gringlobal/CooperatorFilter';
import DateFilter from '@gringlobal/client/model/gringlobal/DateFilter';
import StringFilter from '@gringlobal/client/model/gringlobal/StringFilter';
/**
* SiteFilter
*
* GRIN-Global CE API
*/
class SiteFilter {
public NOT: SiteFilter;
public NULL: string[];
public NOTNULL: string[];
public createdBy: CooperatorFilter;
public createdDate: DateFilter;
public modifiedBy: CooperatorFilter;
public modifiedDate: DateFilter;
public ownedBy: CooperatorFilter;
public ownedDate: DateFilter;
public id: number[];
public faoInstituteNumber: StringFilter;
public distributionSite: boolean;
public internal: boolean;
public note: StringFilter;
public organizationAbbrev: StringFilter;
public providerIdentifier: StringFilter;
public siteLongName: StringFilter;
public siteShortName: StringFilter;
public typeCode: StringFilter;
}
export default SiteFilter;
/**
* StringFilter
*
* GRIN-Global CE API
*/
class StringFilter {
public eq: string;
public contains: string;
public sw: string;
}
export default StringFilter;
import Cooperator from '@gringlobal/client/model/gringlobal/Cooperator';
/**
* SysLang
*
* GRIN-Global CE API
*/
class SysLang {
public createdBy: number;
public createdDate: Date;
public modifiedBy: number;
public modifiedDate: Date;
public ownedBy: Cooperator;
public ownedDate: Date;
public description: string;
public id: number;
public ietfTag: string;
public iso6393Tag: string;
public scriptDirection: string;
public title: string;
}
export default SysLang;
import Geography from '@gringlobal/client/model/gringlobal/Geography';
import WebUser from '@gringlobal/client/model/gringlobal/WebUser';
/**
* WebCooperator
*
* GRIN-Global CE API
*/
class WebCooperator {
public addressLine1: string;
public addressLine2: string;
public addressLine3: string;
public categoryCode: string;
public city: string;
public createdBy: WebUser;
public createdDate: Date;
public discipline: string;
public email: string;
public fax: string;
public firstName: string;
public geography: Geography;
public id: number;
public initials: string;
public isActive: string;
public job: string;
public lastName: string;
public modifiedBy: WebUser;
public modifiedDate: Date;
public note: string;
public organization: string;
public organizationCode: string;
public organizationRegion: string;
public ownedBy: WebUser;
public ownedDate: Date;
public postalIndex: string;
public primaryPhone: string;
public secondaryPhone: string;
public title: string;
}
export default WebCooperator;
import SysLang from '@gringlobal/client/model/gringlobal/SysLang';
import WebCooperator from '@gringlobal/client/model/gringlobal/WebCooperator';
/**
* WebUser
*
* GRIN-Global CE API
*/
class WebUser {
public createdDate: Date;
public id: number;
public isEnabled: string;
public lastLoginDate: Date;
public modifiedDate: Date;
public password: string;
public sysLang: SysLang;
public userName: string;
public webCooperator: WebCooperator;
}
export default WebUser;
import * as UrlTemplate from 'url-template';
import * as QueryString from 'query-string';
import { axiosBackend } from '@gringlobal/client/utilities/requestUtils';
import Cooperator from '@gringlobal/client/model/gringlobal/Cooperator';
import FilteredPage from '@gringlobal/client/model/page/FilteredPage';
import IPageRequest from '@gringlobal/client/model/page/IPageRequest';
const URL_FILTER_1 = '/api/v1/cooperator/filter';
const URL_GET_COOPERATOR = UrlTemplate.parse('/api/v1/cooperator/{id}');
/**
* Cooperator service
*
* GRIN-Global CE API
*/
class CooperatorService {
/**
* filter_1 at /api/v1/cooperator/filter
*
* @param f undefined
* @param page undefined
* @param xhrConfig additional xhr config
*/
public static filter_1(f?: string, page?: IPageRequest, xhrConfig?: any): Promise<FilteredPage<Cooperator>> {
const qs = QueryString.stringify({
f: f || undefined,
p: page.page || undefined,
l: page.size || undefined,
d: page.direction ? page.direction : undefined,
s: page.properties || undefined,
}, {});
const apiUrl = URL_FILTER_1 + (qs ? `?${qs}` : '');
// console.log(`Fetching from ${apiUrl}`);
const content = { /* No content in request body */ };
return axiosBackend.request({
...xhrConfig,
url: apiUrl,
method: 'POST',
...content,
}).then(({ data }) => data as FilteredPage<Cooperator>);
}
/**
* getCooperator at /api/v1/cooperator/{id}
*
* @param id undefined
* @param xhrConfig additional xhr config
*/
public static getCooperator(id: number, xhrConfig?: any): Promise<Cooperator> {
const apiUrl = URL_GET_COOPERATOR.expand({ id });
// console.log(`Fetching from ${apiUrl}`);
const content = { /* No content in request body */ };
return axiosBackend.request({
...xhrConfig,
url: apiUrl,
method: 'GET',
...content,
}).then(({ data }) => data as Cooperator);
}
}
export default CooperatorService;
......@@ -12,6 +12,7 @@ class WelcomePage extends React.Component<WithTranslation> {
<h1>{ t('p.welcome.title') }</h1>
<ul>
<li><Link to="/user">To user list</Link></li>
<li><Link to="/cooperator">To cooperator list</Link></li>
<li><Link to="/login">To login page</Link></li>
</ul>
</>
......
......@@ -56,7 +56,7 @@ export const configureBackendApi = ({ apiUrl, accessToken, origin, timeout }: {
console.log('axiosBackend.defaults.headers', axiosBackend.defaults.headers);
}
if (accessToken) {
console.log('Using backend API accessToken ..snip..', `Bearer ${accessToken}`);
console.log('Using backend API accessToken ..snip..');
axiosBackend.defaults.headers.common.Authorization = `Bearer ${accessToken}`;
}
if (origin) {
......
{
"cooperator": {
"public": {
"p": {
"login": {
"youLoggedIn": "You logged in as {{username}}"
}
}
},
"admin": {
"p": {
"browse": {
"title": "List of users"
}
}
}
},
"user": {
"public": {
"p": {
......
import { put, takeEvery } from 'redux-saga/effects';
// Constants
import {
RECEIVE_COOPERATOR, RECEIVE_COOPERATORS,
SAGA_RECEIVE_COOPERATOR, SAGA_RECEIVE_COOPERATORS,
API_RECEIVE_COOPERATOR, API_RECEIVE_COOPERATORS,
} from 'cooperator/constants';
// Model
import Cooperator from '@gringlobal/client/model/gringlobal/Cooperator';
import { IPageRequest, FilteredPage } from '@gringlobal/client/model/page';
// Service
import CooperatorService from '@gringlobal/client/service/CooperatorService';
export const cooperatorPublicSagas = [
takeEvery(SAGA_RECEIVE_COOPERATOR, getCooperatorSaga),
takeEvery(SAGA_RECEIVE_COOPERATORS, listCooperatorsSaga),
];
// #getUser
export const getCooperatorAction = (id) => ({
type: SAGA_RECEIVE_COOPERATOR,
payload: {
id,
},
});
function* getCooperatorSaga(action) {
const { id } = action.payload;
yield put({
type: API_RECEIVE_COOPERATOR,
method: CooperatorService.getCooperator,
params: [id],
onSuccess: (cooperator) => receiveCooperatorSuccess(cooperator),
});
}
const receiveCooperatorSuccess = (cooperator: Cooperator) => ({
type: RECEIVE_COOPERATOR,
payload: { cooperator },
});
// #listUsers
export const listCooperatorsAction = (filter: string = '', pageR: IPageRequest = { page: 0 }) => ({
type: SAGA_RECEIVE_COOPERATORS,
payload: {
filter,
pageR,
},
});
function * listCooperatorsSaga(action) {
yield put({
type: API_RECEIVE_COOPERATORS,
method: CooperatorService.filter_1,
params: [action.payload.filter, action.payload.pageR],
onSuccess: (cooperators) => receiveCooperatorsSuccess(cooperators),
});
}
const receiveCooperatorsSuccess = (cooperators: FilteredPage<Cooperator>) => ({
type: RECEIVE_COOPERATORS,
payload: { cooperators },
});
export const RECEIVE_COOPERATOR = 'success/cooperator/public/RECEIVE_COOPERATOR';
export const RECEIVE_COOPERATORS = 'success/cooperator/public/RECEIVE_COOPERATORS';
export const SAGA_RECEIVE_COOPERATOR = 'saga/cooperator/public/RECEIVE_COOPERATOR';
export const SAGA_RECEIVE_COOPERATORS = 'saga/cooperator/public/RECEIVE_COOPERATORS';
export const API_RECEIVE_COOPERATOR = 'api/cooperator/public/RECEIVE_COOPERATOR';
export const API_RECEIVE_COOPERATORS = 'api/cooperator/public/RECEIVE_COOPERATORS';
import { combineReducers } from 'redux';
import cooperatorPublic from 'cooperator/reducer/public';
const rootReducer = combineReducers({
public: cooperatorPublic,
});
export default rootReducer;
import update from 'immutability-helper';
// Constants
import { RECEIVE_COOPERATOR, RECEIVE_COOPERATORS } from 'cooperator/constants';
// Model
import Cooperator from '@gringlobal/client/model/gringlobal/Cooperator';
import { FilteredPage } from '@gringlobal/client/model/page';
const initialState: {
cooperators: FilteredPage<Cooperator>,
cooperator: Cooperator,
} = {
cooperators: null,
cooperator: null,
};
const userReducer = (state = initialState, action) => {
switch (action.type) {
case RECEIVE_COOPERATOR: {
const { cooperator } = action.payload;
const { cooperators } = state;
const updatedIndex = cooperators && cooperators.content && cooperators.content.findIndex((userDetails) => userDetails.id === cooperator.id) || -1;
if (updatedIndex !== -1) {
return update(state, {
cooperator: { $set: cooperator },
cooperators: {
[updatedIndex]: { $set: cooperator },
},
});
} else {
return update(state, {
cooperator: { $set: cooperator },
});
}
}
case RECEIVE_COOPERATORS: {
const { cooperators } = action.payload;
return update(state, {