@@ -2,13 +2,147 @@ import React from 'react'
import TestBlock from '../TestBlock'
import './style.css'
import SearchBar from "../SearchBar";
import {Row, InputGroup,Button, ButtonToolbar,
ToggleButtonGroup,
ToggleButton,
ButtonGroup} from "react-bootstrap"
import Toolbar from "../toolbar"
import Select from 'react-select'

class TestsList extends React.Component {
constructor(props, context) {
super(props, context);
this.state = {
show: false,
selectedSystem: null,
tags: [],
sysFilterOpts: null,
standsFilterOpts: null,
selectedFilter: [],
filters: {
tags: [],
systems: null,
stands: null,
}
};
}
componentDidMount() {
this.props.fetchTests();
this.props.getAS();
this.props.getStands();
}

render() {
handleStandsFilterInput = (filterOpts) => {
if (filterOpts !== null) {
this.setState({
filters: {
...this.state.filters,
stands: filterOpts,
}
});
} else {
this.setState({
filters: {
...this.state.filters,
stands: null,
}
});
}
};

handleSysFilterInput = (filterOpts) => {
if (filterOpts !== null) {
this.setState({
filters: {
...this.state.filters,
systems: filterOpts,
}
});
} else {
this.setState({
filters: {
...this.state.filters,
systems: null,
}
});
}
};

handleSearchTagCreation = (tags) => {
if (tags.length > 0) {
this.setState({
filters: {
...this.state.filters,
tags,
}
});
} else {
this.setState({
filters: {
...this.state.filters,
tags: [],
}
});
}
};

handleApplyFiltersBtn = () => {
if (this.state.filters.tags.length > 0) {
let formattedTags = {tag_names: this.state.filters.tags.map(t => t.label)};
this.props.filterTestsByTags(formattedTags, this.state.filters);
} else {
if (this.state.filters.systems !== null || this.state.filters.stands !== null) {
this.props.applyTestsFilters(this.state.filters);
} else {
this.props.clearTestFilter();
}
}
};

clearSearchInputs = (filter) => {
this.props.clearTestFilter();
this.setState({
selectedFilter: filter,
filters: {
tags: [],
systems: null,
stands: null,
}
});
};

handleTestSelection = (index) => {
const {setSelectedTestIndex, systems, testBuilderTests} = this.props;
if (testBuilderTests[index].a_system !== '') {
console.log("Test " + testBuilderTests);
let sysIndex = systems.map(sys => sys.code).indexOf(testBuilderTests[index].a_system);
this.setState({selectedSystem: sysIndex});
} else {
this.setState({selectedSystem: null});
}
setSelectedTestIndex(index);
};

handleSubmitButtonClick = () => {
const {testBuilderTests, selectedTestIndex, testNamesForDropdown, systems, submitCurrentTest} = this.props;
let test = {...testBuilderTests[selectedTestIndex]};
let id = testNamesForDropdown[selectedTestIndex].test_id;
let currentStands = test.stands.map(stand => stand.label);
test.a_system = systems[this.state.selectedSystem].code;
test.stands = currentStands;
submitCurrentTest({test, id});
};

renderSearches = () => {
// const searchMarker = this.props.chainMarkers.map((test, index) => {
// return {label: test, value: index}
// });
// console.log(this.props.testNamesForDropdown);
// const searchOpt = this.props.testNamesForDropdown.map((test, index) => {
// return {label: test.test_name, value: index}
// });
const searchOpt2 = this.props.testNamesForDropdown;
// console.log("drop2 " + this.props.tests);
const tests = this.props.tests || [];
const selectedChainTemplateTests = this.props.selectedChainTemplate.tests || [];
const filteredTests = tests.filter(t => {
@@ -17,15 +151,124 @@ class TestsList extends React.Component {
});
return !testInChain
});
const options = filteredTests.map((test) => {
const searchOpt = filteredTests.map((test) => {
return {label: test.test_name, value: test}
});
const sysToSearchThrough = this.props.systems.map((sys, idx) => {
return {label: sys.code, value: idx}
});
const searchBarSwitcher = () => {
let searches = [];
let filters = [...this.state.selectedFilter];
let applyFiltersBtn = this.state.selectedFilter.length > 0 ? (
<Row>
<Button className={'pull-right'} style={{position: 'relative', marginRight: '14px', marginTop: '5px'}}
onClick={this.handleApplyFiltersBtn}>Применить</Button>
<div className="clearfix"/>
</Row>
) : null;
if (filters.length > 0) {
while (filters.length > 0) {
switch (filters.shift()) {
case 'tags': {
searches.push(
<Select.Creatable
multi
value={this.state.filters.tags}
placeholder={'Фильтрация тестов по тегам...'}
menuStyle={{display: 'none'}}
arrowRenderer={null}
options={[]}
shouldKeyDownEventCreateNewOption={key => key.keyCode = !188}
promptTextCreator={name => name}
onChange={this.handleSearchTagCreation}
/>
);
break;
}

case 'as': {
searches.push(
<Select
className='test-filter'
options={sysToSearchThrough}
placeholder={'Фильтрация тестов по АС...'}
onChange={this.handleSysFilterInput}
value={this.state.filters.systems}
/>
);
break;
}

case 'stand': {
searches.push(
<Select
className='test-filter'
options={this.props.stands}
placeholder={'Фильтрация тестов по контуру...'}
onChange={this.handleStandsFilterInput}
value={this.state.filters.stands}
/>
);
break;
}

default:
break;
}

}
}
searches.push(applyFiltersBtn);
return searches;
};

return [
<SearchBar options={searchOpt} placeholder={'Поиск теста по названию...'}
onOptionClick={this.handleTestSelection}/>,
<InputGroup style={{marginBottom: '5px', marginTop: '5px'}}>
<InputGroup.Addon>Фильтры:</InputGroup.Addon>
<ButtonToolbar>
<ButtonGroup>
<ToggleButtonGroup type='checkbox' name='searchesSwitcher' value={this.state.selectedFilter}
onChange={searchType => this.clearSearchInputs(searchType)}>
<ToggleButton style={{borderRadius: '0'}} value={'tags'}>Тегам</ToggleButton>
<ToggleButton value={'as'}>АС</ToggleButton>
<ToggleButton value={'stand'}>Контуру</ToggleButton>
</ToggleButtonGroup>
{this.state.selectedFilter.length > 0
? <Button bsStyle='danger'
onClick={() => this.clearSearchInputs([])}>Сброс</Button>
: null}
</ButtonGroup>
</ButtonToolbar>
</InputGroup>,
searchBarSwitcher()
];
};

render() {
const tests = this.props.tests || [];
const selectedChainTemplateTests = this.props.selectedChainTemplate.tests || [];
const filteredTests = tests.filter(t => {
const testInChain = selectedChainTemplateTests.find((element) => {
return element.id === t.test_id
});
return !testInChain
});
// const options = filteredTests.map((test) => {
// return {label: test.test_name, value: test}
// });
return [
<ol>
<SearchBar
options={options}
onOptionClick={this.props.testBlockClicked}
<Toolbar
style={{marginLeft: 10}}
additionalElement={this.renderSearches()}
/>
{/*<SearchBar*/}
{/*options={options}*/}
{/*onOptionClick={this.props.testBlockClicked}*/}
{/*/>*/}
{filteredTests.map((test, idx) => {
return (
<div className='use-test-button' onClick={() => {
@@ -42,6 +42,7 @@ export const ON_FIELDS_VALUES_UPDATE = 'ON_FIELDS_VALUES_UPDATE';
export const FIELD_WAS_REMOVED = 'FIELD_WAS_REMOVED';

export const TEST_BUILDER_TESTS_FETCH_SUCCEED = 'TEST_BUILDER_TESTS_FETCH_SUCCEED';
export const TEST_LIST_TESTS_FETCH_SUCCEED = 'TEST_LIST_TESTS_FETCH_SUCCEED';
export const TEST_SELECTED = 'TEST_SELECTED';
export const TEST_BUILDER_FORM_INPUT_CHANGED = 'TEST_BUILDER_FORM_INPUT_CHANGED';
export const ADD_NEW_TEST = 'ADD_NEW_TEST';
@@ -1,21 +1,50 @@
import {connect} from 'react-redux'
import {fetchTests} from '../api'
import {
fetchTests, filterEntityByTags, getDictionaryData, submitTest, testBuilderDataFetch,
testListDataFetch
} from '../api'
import TestsList from '../components/TestsList'
import {testBlockClicked} from '../actions'
import {
applyTestsFilters,
clearTestFilter, duplicateCurrentTest, filteredTestByTagsFetchSucceed, newTestAdded, testASSelected, testBlockClicked,
testBuilderAsFetchSucceed, testBuilderFormInputChanged,
testBuilderStandsFetchSucceed,
testSelected, testStandsInputChange
} from '../actions'
import test from "../reducers/test";

function mapStateToProps(state) {
return {
tests: state.test,
selectedChainTemplate: state.chainTemplates.chainTemplates[state.chainTemplates.selectedChainTemplate] || {
tests: []
},
testBuilderTests: state.testList.testBuilderTests,
notifications: state.notifications,
selectedTestIndex: state.testList.selectedTestIndex,
testNamesForDropdownTwo: state.testList.testNamesForDropdownTwo,
// testNamesForDropdown: state.test,
testName: state.testList.testName,
owner: state.dataAuthorization.paramNames.name,
systems: state.testList.systems,
stands: state.testList.stands,
}
}

function mapDispatchToProps(dispatch) {
return {
fetchTests: () => dispatch(fetchTests()),
testBlockClicked: (test) => dispatch(testBlockClicked(test))
// getTests: () => dispatch(testBuilderDataFetch()),
fetchTests: () => dispatch(fetchTests()),
testBlockClicked: (test) => dispatch(testBlockClicked(test)),
getTests: () => dispatch(testListDataFetch()),
setSelectedTestIndex: (index) => dispatch(testSelected(index)),
submitCurrentTest: (testObject) => dispatch(submitTest(testObject)),
getAS: () => dispatch(getDictionaryData('systems', testBuilderAsFetchSucceed)),
getStands: () => dispatch(getDictionaryData('stands', testBuilderStandsFetchSucceed)),
sysIndexChanged: (index) => dispatch(testASSelected(index)),
filterTestsByTags: (tags, filters) => dispatch(filterEntityByTags(tags, 'tests', filteredTestByTagsFetchSucceed, filters)),
clearTestFilter: () => dispatch(clearTestFilter()),
applyTestsFilters: (filters) => dispatch(applyTestsFilters(filters)),
}
}

@@ -12,6 +12,7 @@ import dataTemplatesBuilderReducer from "./DataTemplates"
import dataDirectory from './dataDirectory'
import dataAuthorization from './dataAuthorization'
import dataPersonal from "./dataPersonal";
import testList from "./testList";


const rootReducer = combineReducers({
@@ -28,6 +29,7 @@ const rootReducer = combineReducers({
dataTemplatesBuilderReducer,
notifications,
dataDirectory,
testList,
});

export default rootReducer
@@ -1,8 +1,11 @@
import {
TEST_FETCH_SUCCEED,
TEST_FETCH_SUCCEED
} from '../constants'

const initialState = null;
// const initialState = {
// stands: [],
// };

const testReducer = (state = initialState, action) => {
switch (action.type) {
@@ -12,6 +15,7 @@ const testReducer = (state = initialState, action) => {
default:
return state
}
console.log("pay - " + action.payload);
};

export default testReducer
@@ -0,0 +1,280 @@
import {
TEST_BUILDER_TESTS_FETCH_SUCCEED,
TEST_SELECTED,
TEST_BUILDER_FORM_INPUT_CHANGED,
ADD_NEW_TEST,
RESET_MODIFICATION_MARKERS,
TEST_BUILDER_AS_FETCH_SUCCEED,
TEST_AS_SELECTED,
TEST_BUILDER_STANDS_FETCH_SUCCEED,
DUPLICATE_CURRENT_TEST,
TEST_STANDS_INPUT_CHANGE,
CLEAR_TEST_FILTER,
FILTERED_TEST_BY_TAGS_FETCH_SUCCEED,
APPLY_TESTS_FILTERS,
TEST_LIST_TESTS_FETCH_SUCCEED,
} from '../constants'

const initialState = {
testBuilderTests: [],
selectedTestIndex: null,
testNamesForDropdown: [],
systems: [],
stands: [],
testsOrigin: [],
};

const MODULE_MAIN = '#/chaineditor/';

const testList = (state = initialState, action) => {
switch (action.type) {
case TEST_LIST_TESTS_FETCH_SUCCEED: {
console.log("БЫЛ ТУТ!")
const testNamesForDropdownTwo = action.payload.map((test) => {
return {
test_name: test.test_name,
test_id: test.test_id,
}
});
const tests = [...action.payload];
const adaptedTests = tests.map((current) => {
current.modified = false;
current.new = false;
if (!current.tag_names.static) {
current.tag_names.static = [];
} else {
let tmp = [...current.tag_names.static];
current.tag_names.static = tmp.map((tag, index) => {
return {label: tag, value: index}
});
}
if (!current.tag_names.dynamic) {
current.tag_names.dynamic = [];
} else {
let tmp = [...current.tag_names.dynamic];
current.tag_names.dynamic = tmp.map((tag, index) => {
return {label: tag, value: index}
});
}
if (!current.a_system) {
current.a_system = '';
}
if (current.stands.length > 0) {
current.stands = current.stands.map((s, index) => {
return {label: s, value: index}
});
}
return current;
});
return {
...state,
testBuilderTests: adaptedTests,
testNamesForDropdownTwo: testNamesForDropdownTwo,
selectedTestIndex: null,
testsOrigin: adaptedTests,
}
}

case TEST_BUILDER_AS_FETCH_SUCCEED: {
return {
...state,
systems: action.as,
}
}

case TEST_SELECTED: {
window.location.hash = MODULE_MAIN + state.testBuilderTests[action.payload].test_name;
return {
...state,
selectedTestIndex: action.payload,
}
}

case TEST_AS_SELECTED: {
let testBuilderTests = [...state.testBuilderTests];
testBuilderTests[state.selectedTestIndex].a_system = state.systems[action.index].code;
const newTest = testBuilderTests[state.selectedTestIndex].new;
testBuilderTests[state.selectedTestIndex].modified = !newTest;
return {
...state,
testBuilderTests,
}
}

case TEST_BUILDER_STANDS_FETCH_SUCCEED: {
const stands = action.stands.map((stand, index) => {
return {label: stand.code, value: index}
});
return {
...state,
stands,
}
}

case CLEAR_TEST_FILTER: {
const testBuilderTests = [...state.testsOrigin];
const testNamesForDropdownTwo = [...state.testsOrigin].map((test) => {
return {
test_name: test.test_name,
test_id: test.test_id,
}
});
return {
...state,
testBuilderTests,
testNamesForDropdownTwo,
}
}

case FILTERED_TEST_BY_TAGS_FETCH_SUCCEED: {
const tests = [...action.tests];
const adaptedTests = tests.map((current) => {
current.modified = false;
current.new = false;
if (!current.tag_names.static) {
current.tag_names.static = [];
} else {
let tmp = [...current.tag_names.static];
current.tag_names.static = tmp.map((tag, index) => {
return {label: tag, value: index}
});
}
if (!current.tag_names.dynamic) {
current.tag_names.dynamic = [];
} else {
let tmp = [...current.tag_names.dynamic];
current.tag_names.dynamic = tmp.map((tag, index) => {
return {label: tag, value: index}
});
}
if (!current.a_system) {
current.a_system = '';
}
if (current.stands.length > 0) {
current.stands = current.stands.map((s, index) => {
return {label: s, value: index}
});
}
return current;
});
const origin = [...adaptedTests];
const filters = action.filters;
let filtersAllied = [];

if (filters.systems !== null && filters.stands !== null) {
origin.map(t => {
let sys = false;
let stand = false;
if (t.a_system === filters.systems.label) {
sys = true;
}
if (t.stands.length > 0) {
t.stands.map(s => {
if (s.label === filters.stands.label) stand = true;
});
}
if (sys && stand) filtersAllied.push(t);
});
} else {
if (filters.systems !== null) {
origin.map(t => {
if (t.a_system === filters.systems.label) {
filtersAllied.push(t);
}
});
} else {
if (filters.stands !== null) {
origin.map(t => {
if (t.stands.length > 0)
t.stands.map(s => {
if (s.label === filters.stands.label) filtersAllied.push(t);
});
});
} else {
filtersAllied = origin;
}
}

}

let testBuilderTests = filtersAllied;

const testNamesForDropdownTwo = testBuilderTests.map((test) => {
return {
test_name: test.test_name,
test_id: test.test_id,
}
});

window.location.hash = MODULE_MAIN;
return {
...state,
testBuilderTests,
testNamesForDropdownTwo,
selectedTestIndex: null,
}
}

case APPLY_TESTS_FILTERS: {
const origin = [...state.testsOrigin];
const filters = action.filters;
let filtersAllied = [];

if (filters.systems !== null && filters.stands !== null) {
origin.map(t => {
let sys = false;
let stand = false;
if (t.a_system === filters.systems.label) {
sys = true;
}
if (t.stands.length > 0) {
t.stands.map(s => {
if (s.label === filters.stands.label) stand = true;
});
}
if (sys && stand) filtersAllied.push(t);
});
} else {
if (filters.systems !== null) {
origin.map(t => {
if (t.a_system === filters.systems.label) {
filtersAllied.push(t);
}
});
} else {
if (filters.stands !== null) {
origin.map(t => {
if (t.stands.length > 0)
t.stands.map(s => {
if (s.label === filters.stands.label) filtersAllied.push(t);
});
});
} else {
filtersAllied = origin;
}
}

}
let testBuilderTests = filtersAllied;
const testNamesForDropdownTwo = testBuilderTests.map((test) => {
return {
test_name: test.test_name,
test_id: test.test_id,
}
});

return {
...state,
testBuilderTests,
testNamesForDropdownTwo,
selectedTestIndex: null,
}
}

default:
return {
...state,
}
}
};
export default testList