From b5774bba01b44cef7db0c67f40031b3dfbfe6f35 Mon Sep 17 00:00:00 2001 From: Vivek205 Date: Fri, 3 May 2019 16:24:35 +0530 Subject: [PATCH 1/6] dev completed, yet to test --- src/components/ReactStyles.js | 14 ++---- src/components/Services.js | 86 +++++++++++++++++++++-------------- src/util.js | 6 ++- 3 files changed, 62 insertions(+), 44 deletions(-) diff --git a/src/components/ReactStyles.js b/src/components/ReactStyles.js index ae2f0fb..6ae89fe 100644 --- a/src/components/ReactStyles.js +++ b/src/components/ReactStyles.js @@ -70,16 +70,10 @@ export const theme = createMuiTheme({ overrides: { MuiButton: { root: { - background: 'white', - borderRadius: 3, - border: 0, - color: 'white', - height: 38, - padding: '0 30px', - boxShadow: '0 3px 5px 2px lightblue', - fontFamily: "Muli", - fontSize: "12px", - }, + height: 38, + fontFamily: "Muli", + fontSize: "18px", + }, }, }, }); \ No newline at end of file diff --git a/src/components/Services.js b/src/components/Services.js index b75b0be..3aad278 100644 --- a/src/components/Services.js +++ b/src/components/Services.js @@ -4,7 +4,7 @@ import { MuiThemeProvider } from "@material-ui/core/styles" import Pagination from "material-ui-flat-pagination" import Typography from '@material-ui/core/Typography' import { withRouter } from 'react-router-dom' -import { AGI, getMarketplaceURL, isSupportedNetwork } from '../util' +import { AGI, getMarketplaceURL, isSupportedNetwork, generateSearchString } from '../util' import { Requests } from '../requests' import BlockchainHelper from "./BlockchainHelper.js" import {Jobdetails} from './JobDetails.js'; @@ -31,14 +31,15 @@ class SampleServices extends React.Component { this.account = undefined; this.onOpenJobDetailsSlider = this.onOpenJobDetailsSlider.bind(this) this.onCloseJobDetailsSlider = this.onCloseJobDetailsSlider.bind(this) - this.captureSearchTerm = this.captureSearchTerm.bind(this) + this.handleSearch = this.handleSearch.bind(this) this.handlepricesort = this.handlepricesort.bind(this) this.handleservicenamesort = this.handleservicenamesort.bind(this) this.handlehealthsort = this.handlehealthsort.bind(this) - this.handleSearchKeyUp = this.handleSearchKeyUp.bind(this) + // this.handleSearchKeyUp = this.handleSearchKeyUp.bind(this) this.watchWalletTimer = undefined; this.watchNetworkTimer = undefined; this.loadDetails = this.loadDetails.bind(this); + this.handlePagination = this.handlePagination.bind(this); } watchWallet() { @@ -69,26 +70,26 @@ class SampleServices extends React.Component { return false; } - handleSearchKeyUp(e) { - e.preventDefault(); - if(this.state.searchTerm === '') { - this.setState({searchResults:[]}); - return; - } + // handleSearchKeyUp(e) { + // e.preventDefault(); + // if(this.state.searchTerm === '') { + // this.setState({searchResults:[]}); + // return; + // } - let ucSearchTerm = this.state.searchTerm.toUpperCase(); - this.state.agents.map(row => - (this.inArray(row["tags_uc"], ucSearchTerm)) ? - console.log("Matched " + row["tags_uc"]) : console.log("Not Matched " + row["tags_uc"])) + // let ucSearchTerm = this.state.searchTerm.toUpperCase(); + // this.state.agents.map(row => + // (this.inArray(row["tags_uc"], ucSearchTerm)) ? + // console.log("Matched " + row["tags_uc"]) : console.log("Not Matched " + row["tags_uc"])) - let searchedagents = this.state.agents.map(row => - (row["display_name_uc"].indexOf(ucSearchTerm) !== -1 - || (this.inArray(row["tags_uc"], ucSearchTerm)) ? row : null)) + // let searchedagents = this.state.agents.map(row => + // (row["display_name_uc"].indexOf(ucSearchTerm) !== -1 + // || (this.inArray(row["tags_uc"], ucSearchTerm)) ? row : null)) - let bestsearchresults = [...(searchedagents.filter(row => row !== null).map(row1 => row1))] - console.log("Setting search results to " + bestsearchresults.length) - this.setState({searchResults:bestsearchresults}); - } + // let bestsearchresults = [...(searchedagents.filter(row => row !== null).map(row1 => row1))] + // console.log("Setting search results to " + bestsearchresults.length) + // this.setState({searchResults:bestsearchresults}); + // } handlehealthsort() { var healthSort = this.state.agents @@ -237,8 +238,20 @@ class SampleServices extends React.Component { this.setState({userAddress: web3.eth.defaultAccount}); } - handleClick(offset) { + handlePagination(offset) { this.setState({ offset }); + let marketPlaceURL = getMarketplaceURL(this.state.chainId); + let searchTerm = this.state.searchTerm; + let searchURL = generateSearchString({marketPlaceURL,searchTerm,offset}); + Requests.get(searchURL).then(response=>{ + console.log('response',response); + if(response.status === 'success'){ + let { result:agents, offset } = response.data; + this.setState({agents,offset}); + } + }).catch(err=>{ + console.log('error',err); + }); } onOpenJobDetailsSlider(data) { @@ -249,21 +262,28 @@ class SampleServices extends React.Component { this.refs.jobdetailsComp.onCloseJobDetailsSlider(); } - captureSearchTerm(e) { - this.setState({searchTerm:e.target.value}) + handleSearch(e) { + let marketPlaceURL = getMarketplaceURL(this.state.chainId); + let searchTerm = e.target.value; + this.setState({searchTerm}); + let searchURL = generateSearchString({marketPlaceURL,searchTerm}) + Requests.get(searchURL).then(response=>{ + // console.log('response',response); + if(response.status === 'success'){ + let { result:agents, offset } = response.data; + this.setState({agents,offset}); + } + }).catch(err=>{ + console.log('error',err); + }); + } render() { - const {open} = this.state; let arraylimit = this.state.agents.length - let agentsample = this.state.agents - if (this.state.searchTerm != '' || this.state.searchResults.length > 0) { - agentsample = this.state.searchResults - arraylimit = this.state.searchResults.length - } - const agents = agentsample.slice(this.state.offset, this.state.offset + 15).map((rown,index) => + const agents = agentsample.slice(0,15).map((rown,index) =>
Agent Name
@@ -326,7 +346,7 @@ class SampleServices extends React.Component { Service Agents
- this.handleSearchKeyUp(e)} /> +
@@ -370,10 +390,10 @@ class SampleServices extends React.Component {
{agents}
-
+
{arraylimit>15? - this.handleClick(offset)} /> + this.handlePagination(offset)} /> :null}
diff --git a/src/util.js b/src/util.js index 98623bf..8b67219 100644 --- a/src/util.js +++ b/src/util.js @@ -149,4 +149,8 @@ export function isSupportedNetwork(chainId) { } export const BLOCK_OFFSET = 80640 //# Approximately blocks generated in 30 minutes -export const BLOCK_TIME_SECONDS = 15 // Number of seconds, a single block unit corresponds to. \ No newline at end of file +export const BLOCK_TIME_SECONDS = 15 // Number of seconds, a single block unit corresponds to. + +export const generateSearchString = ({marketPlaceURL,searchTerm,field='all',limit=15,offset=0}) =>{ + return `${marketPlaceURL}search?q=${searchTerm}&s=${field}&limit=${limit}&offset=${offset}`; +} \ No newline at end of file From a6d74251390af10a3d7fc26c7dbdbdbcd8071070 Mon Sep 17 00:00:00 2001 From: Vivek205 Date: Fri, 3 May 2019 17:24:28 +0530 Subject: [PATCH 2/6] pagination total --- src/components/Services.js | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/components/Services.js b/src/components/Services.js index 3aad278..bc49c1a 100644 --- a/src/components/Services.js +++ b/src/components/Services.js @@ -17,6 +17,7 @@ class SampleServices extends React.Component { super(props); this.state = { agents : [], + paginationTotal:0, offset:0, searchTerm:'', searchResults:[], @@ -174,7 +175,7 @@ class SampleServices extends React.Component { loadDetails(chainId) { if(!isSupportedNetwork(chainId)) { - this.setState({agents:[]}) + this.setState({agents:[],paginationTotal:0}) return; } const marketPlaceURL = getMarketplaceURL(chainId); @@ -221,7 +222,7 @@ class SampleServices extends React.Component { } })) } - this.setState({agents: values[0].data}) + this.setState({agents: values[0].data,paginationTotal:values[0].data.length}) } } //Do this the first time the page gets loaded. @@ -246,8 +247,8 @@ class SampleServices extends React.Component { Requests.get(searchURL).then(response=>{ console.log('response',response); if(response.status === 'success'){ - let { result:agents, offset } = response.data; - this.setState({agents,offset}); + let { result:agents, offset, total_count:paginationTotal } = response.data; + this.setState({agents,offset,paginationTotal}); } }).catch(err=>{ console.log('error',err); @@ -270,8 +271,8 @@ class SampleServices extends React.Component { Requests.get(searchURL).then(response=>{ // console.log('response',response); if(response.status === 'success'){ - let { result:agents, offset } = response.data; - this.setState({agents,offset}); + let { result:agents, offset, total_count:paginationTotal } = response.data; + this.setState({agents,offset, paginationTotal}); } }).catch(err=>{ console.log('error',err); @@ -280,7 +281,6 @@ class SampleServices extends React.Component { } render() { - let arraylimit = this.state.agents.length let agentsample = this.state.agents const agents = agentsample.slice(0,15).map((rown,index) => @@ -391,9 +391,9 @@ class SampleServices extends React.Component { {agents}
- {arraylimit>15? + {this.state.paginationTotal>15? - this.handlePagination(offset)} /> + this.handlePagination(offset)} /> :null}
From 16d98eec1315e9039914ddb47866c249335cac4c Mon Sep 17 00:00:00 2001 From: Vivek205 Date: Fri, 3 May 2019 17:39:57 +0530 Subject: [PATCH 3/6] added sort_by and order_by in searchString --- src/util.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/util.js b/src/util.js index 8b67219..44e7ec6 100644 --- a/src/util.js +++ b/src/util.js @@ -151,6 +151,6 @@ export function isSupportedNetwork(chainId) { export const BLOCK_OFFSET = 80640 //# Approximately blocks generated in 30 minutes export const BLOCK_TIME_SECONDS = 15 // Number of seconds, a single block unit corresponds to. -export const generateSearchString = ({marketPlaceURL,searchTerm,field='all',limit=15,offset=0}) =>{ - return `${marketPlaceURL}search?q=${searchTerm}&s=${field}&limit=${limit}&offset=${offset}`; +export const generateSearchString = ({marketPlaceURL,searchTerm,field='all',limit=15,offset=0,sort_by='dn',order_by='desc'}) =>{ + return `${marketPlaceURL}search?q=${searchTerm}&s=${field}&limit=${limit}&offset=${offset}&sort_by=${sort_by}&order_by=${order_by}`; } \ No newline at end of file From 994bc348dea865a319ecc0ace34f6372774e6851 Mon Sep 17 00:00:00 2001 From: Vivek205 Date: Mon, 6 May 2019 17:55:25 +0530 Subject: [PATCH 4/6] taking the missing data from masterData --- src/components/Services.js | 66 +++++++++++++++++++++----------------- 1 file changed, 36 insertions(+), 30 deletions(-) diff --git a/src/components/Services.js b/src/components/Services.js index bc49c1a..6e6a395 100644 --- a/src/components/Services.js +++ b/src/components/Services.js @@ -28,6 +28,8 @@ class SampleServices extends React.Component { chainId: undefined }; + this.masterData=[] + this.network = new BlockchainHelper(); this.account = undefined; this.onOpenJobDetailsSlider = this.onOpenJobDetailsSlider.bind(this) @@ -36,11 +38,11 @@ class SampleServices extends React.Component { this.handlepricesort = this.handlepricesort.bind(this) this.handleservicenamesort = this.handleservicenamesort.bind(this) this.handlehealthsort = this.handlehealthsort.bind(this) - // this.handleSearchKeyUp = this.handleSearchKeyUp.bind(this) this.watchWalletTimer = undefined; this.watchNetworkTimer = undefined; this.loadDetails = this.loadDetails.bind(this); this.handlePagination = this.handlePagination.bind(this); + this.parseSearchResult = this.parseSearchResult.bind(this); } watchWallet() { @@ -71,27 +73,6 @@ class SampleServices extends React.Component { return false; } - // handleSearchKeyUp(e) { - // e.preventDefault(); - // if(this.state.searchTerm === '') { - // this.setState({searchResults:[]}); - // return; - // } - - // let ucSearchTerm = this.state.searchTerm.toUpperCase(); - // this.state.agents.map(row => - // (this.inArray(row["tags_uc"], ucSearchTerm)) ? - // console.log("Matched " + row["tags_uc"]) : console.log("Not Matched " + row["tags_uc"])) - - // let searchedagents = this.state.agents.map(row => - // (row["display_name_uc"].indexOf(ucSearchTerm) !== -1 - // || (this.inArray(row["tags_uc"], ucSearchTerm)) ? row : null)) - - // let bestsearchresults = [...(searchedagents.filter(row => row !== null).map(row1 => row1))] - // console.log("Setting search results to " + bestsearchresults.length) - // this.setState({searchResults:bestsearchresults}); - // } - handlehealthsort() { var healthSort = this.state.agents if (this.state.togglehealth === false) { @@ -221,7 +202,8 @@ class SampleServices extends React.Component { agent["is_available"] = healthDetail["is_available"] } })) - } + } + this.masterData= values[0].data; this.setState({agents: values[0].data,paginationTotal:values[0].data.length}) } } @@ -245,9 +227,9 @@ class SampleServices extends React.Component { let searchTerm = this.state.searchTerm; let searchURL = generateSearchString({marketPlaceURL,searchTerm,offset}); Requests.get(searchURL).then(response=>{ - console.log('response',response); if(response.status === 'success'){ - let { result:agents, offset, total_count:paginationTotal } = response.data; + let { offset, total_count:paginationTotal } = response.data; + let agents = this.parseSearchResult(response); this.setState({agents,offset,paginationTotal}); } }).catch(err=>{ @@ -269,10 +251,10 @@ class SampleServices extends React.Component { this.setState({searchTerm}); let searchURL = generateSearchString({marketPlaceURL,searchTerm}) Requests.get(searchURL).then(response=>{ - // console.log('response',response); if(response.status === 'success'){ - let { result:agents, offset, total_count:paginationTotal } = response.data; - this.setState({agents,offset, paginationTotal}); + let { offset, total_count:paginationTotal } = response.data; + let agents = this.parseSearchResult(response); + this.setState({agents, offset, paginationTotal}); } }).catch(err=>{ console.log('error',err); @@ -280,6 +262,25 @@ class SampleServices extends React.Component { } + parseSearchResult(response){ + let {result:searchResults} = response.data; + if(!Array.isArray(searchResults) || (searchResults.length == 0)){ return []} + searchResults.map(srchRslt=>{ + this.masterData.map(agent=>{ + if(srchRslt["service_id"] === agent["service_id"] && srchRslt["org_id"] === agent["org_id"]){ + srchRslt["is_available"] = agent["is_available"]; + srchRslt["price_in_agi"] = agent["price_in_agi"]; + srchRslt["comment"] = agent["comment"]; + srchRslt["down_vote"] = agent["down_vote"]; + srchRslt["down_vote_count"] = agent["down_vote_count"]; + srchRslt["up_vote"] = agent["up_vote"]; + srchRslt["up_vote_count"] = agent["up_vote_count"]; + } + }); // end of agents map + }); // end of searchResults map + return searchResults; + } + render() { let agentsample = this.state.agents @@ -346,7 +347,12 @@ class SampleServices extends React.Component { Service Agents
- +
@@ -391,7 +397,7 @@ class SampleServices extends React.Component { {agents}
- {this.state.paginationTotal>15? + {this.state.agents.length>15? this.handlePagination(offset)} /> From 14b8038d6760188ffc31c336b0bfb91dd5b32dd3 Mon Sep 17 00:00:00 2001 From: Vivek205 Date: Tue, 7 May 2019 10:24:30 +0530 Subject: [PATCH 5/6] checking length of agents OR pagination total --- src/components/Services.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/Services.js b/src/components/Services.js index 6e6a395..3a55733 100644 --- a/src/components/Services.js +++ b/src/components/Services.js @@ -397,7 +397,7 @@ class SampleServices extends React.Component { {agents}
- {this.state.agents.length>15? + {(this.state.agents.length>15 || this.state.paginationTotal > 15)? this.handlePagination(offset)} /> From 74503279904e8b76ef397baa5f43e41b6426f4ce Mon Sep 17 00:00:00 2001 From: Vivek205 Date: Tue, 7 May 2019 11:35:54 +0530 Subject: [PATCH 6/6] renaming generateSearchString to generateSearchURL --- src/components/Services.js | 6 +++--- src/util.js | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/components/Services.js b/src/components/Services.js index 3a55733..cb5f2b1 100644 --- a/src/components/Services.js +++ b/src/components/Services.js @@ -4,7 +4,7 @@ import { MuiThemeProvider } from "@material-ui/core/styles" import Pagination from "material-ui-flat-pagination" import Typography from '@material-ui/core/Typography' import { withRouter } from 'react-router-dom' -import { AGI, getMarketplaceURL, isSupportedNetwork, generateSearchString } from '../util' +import { AGI, getMarketplaceURL, isSupportedNetwork, generateSearchURL } from '../util' import { Requests } from '../requests' import BlockchainHelper from "./BlockchainHelper.js" import {Jobdetails} from './JobDetails.js'; @@ -225,7 +225,7 @@ class SampleServices extends React.Component { this.setState({ offset }); let marketPlaceURL = getMarketplaceURL(this.state.chainId); let searchTerm = this.state.searchTerm; - let searchURL = generateSearchString({marketPlaceURL,searchTerm,offset}); + let searchURL = generateSearchURL({marketPlaceURL,searchTerm,offset}); Requests.get(searchURL).then(response=>{ if(response.status === 'success'){ let { offset, total_count:paginationTotal } = response.data; @@ -249,7 +249,7 @@ class SampleServices extends React.Component { let marketPlaceURL = getMarketplaceURL(this.state.chainId); let searchTerm = e.target.value; this.setState({searchTerm}); - let searchURL = generateSearchString({marketPlaceURL,searchTerm}) + let searchURL = generateSearchURL({marketPlaceURL,searchTerm}) Requests.get(searchURL).then(response=>{ if(response.status === 'success'){ let { offset, total_count:paginationTotal } = response.data; diff --git a/src/util.js b/src/util.js index 44e7ec6..4ec8a31 100644 --- a/src/util.js +++ b/src/util.js @@ -151,6 +151,6 @@ export function isSupportedNetwork(chainId) { export const BLOCK_OFFSET = 80640 //# Approximately blocks generated in 30 minutes export const BLOCK_TIME_SECONDS = 15 // Number of seconds, a single block unit corresponds to. -export const generateSearchString = ({marketPlaceURL,searchTerm,field='all',limit=15,offset=0,sort_by='dn',order_by='desc'}) =>{ +export const generateSearchURL = ({marketPlaceURL,searchTerm,field='all',limit=15,offset=0,sort_by='dn',order_by='desc'}) =>{ return `${marketPlaceURL}search?q=${searchTerm}&s=${field}&limit=${limit}&offset=${offset}&sort_by=${sort_by}&order_by=${order_by}`; } \ No newline at end of file