Advertisement
Guest User

Untitled

a guest
Jan 15th, 2019
267
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 35.22 KB | None | 0 0
  1. import {Col, Button, Form, FormGroup, Label} from 'react-bootstrap';
  2. import {CountyService, UserService, getCounties} from "../../services";
  3. import {Component} from 'react';
  4. import * as React from 'react';
  5. import {Alert} from "../../widgets";
  6. import ReactDOM from 'react-dom';
  7. import {County} from "../../classTypes";
  8. import DropdownButton from "react-bootstrap/es/DropdownButton";
  9. import MenuItem from "react-bootstrap/es/MenuItem";
  10. import Grid from "react-bootstrap/es/Grid";
  11. import {FormControl, PageHeader} from "react-bootstrap";
  12. import Checkbox from "react-bootstrap/es/Checkbox";
  13. import Select from "react-select";
  14.  
  15. let countyService = new CountyService();
  16. let userService = new UserService();
  17.  
  18. interface State{
  19. mail: string;
  20. firstName: string;
  21. lastName: string;
  22. password: string;
  23. password2: string;
  24. typeName: string;
  25. phone: string;
  26. points: number;
  27. countyId: number;
  28. countyName: string;
  29. active: number;
  30. isLoaded: boolean;
  31. }
  32. interface Props{
  33. match: Object,
  34. }
  35.  
  36. /*class BindDropDown extends Component {
  37. constructor(props) {
  38. super(props);
  39. this.state = {
  40. choosen: {name: "Bergen", countyId: 1},
  41. values:[
  42. {name: "Bergen", countyId: 1}
  43. //{ name: this.county.name, countyId: this.county.countyId}
  44. ]
  45. }
  46.  
  47. this.handleChangeCounty = this.handleChangeCounty.bind(this)
  48. }
  49.  
  50. handleChangeCounty(e: Object){
  51. console.log(this.state.choosen.countyId)
  52. this.setState({
  53. choosen: JSON.parse(e.target.value)
  54. })
  55.  
  56.  
  57. };
  58.  
  59. componentWillMount() {
  60. var arr = [];
  61. countyService
  62. .getCounties()
  63. .then(county2 => {
  64. county2.map(e => {
  65. var elem = {
  66. name: e.name,
  67. countyId: e.countyId
  68. };
  69. arr = arr.concat(elem)
  70.  
  71. });
  72. this.setState({
  73. values: arr
  74. })
  75. })
  76.  
  77.  
  78. //this.state.countyName.push(this.state.county.name)})
  79. .catch((error: Error)=>Alert.danger(error.message))
  80.  
  81. }
  82.  
  83.  
  84.  
  85. render(){
  86. let optionTemplate = this.state.values.map(v => {
  87. var data = {name: v.name, countyId: v.countyId}
  88. return(<option key={v.countyId} value={JSON.stringify(data)}> {v.name}</option>)
  89. });
  90. return (
  91. <label>
  92. Velg Kommune:
  93. <select value={this.state.values.countyId} onChange={this.handleChangeCounty}>
  94. {optionTemplate}
  95. </select>
  96. </label>
  97. )
  98. }
  99. }*/
  100.  
  101. export class RegisterUser extends Component<Props, State>{
  102.  
  103. /*state = {
  104. mail: "",
  105. firstName: "",
  106. lastName: "",
  107. postnumber: 0,
  108. password: "",
  109. password2: "",
  110. typeName: "",
  111. phone: 0,
  112. points: 0,
  113. active: 0,
  114. isLoaded: false,
  115. };*/
  116. constructor(props) {
  117. super(props);
  118. this.state = {
  119. mail: "",
  120. firstName: "",
  121. lastName: "",
  122. postnumber: 0,
  123. password: "",
  124. password2: "",
  125. typeName: "",
  126. phone: "",
  127. points: 0,
  128. active: 0,
  129. isLoaded: false,
  130. choosen: {label: "Bergen", countyId: 1},
  131. values:[
  132. {label: "Bergen", countyId: 1}
  133. //{ name: this.county.name, countyId: this.county.countyId}
  134. ]
  135. }
  136.  
  137. this.handleChangeCounty = this.handleChangeCounty.bind(this)
  138. }
  139.  
  140.  
  141. handleChangeCounty(e: Object){
  142. this.setState({
  143. choosen: JSON.parse(e.value)
  144. })
  145. };
  146.  
  147. componentWillMount() {
  148. var arr = [];
  149. countyService
  150. .getCounties()
  151. .then(county2 => {
  152. county2.map(e => {
  153. var elem = {
  154. name: e.name,
  155. countyId: e.countyId
  156. };
  157. arr = arr.concat(elem)
  158.  
  159. });
  160. this.setState({
  161. values: arr
  162. })
  163. })
  164.  
  165.  
  166. //this.state.countyName.push(this.state.county.name)})
  167. .catch((error: Error)=>Alert.danger(error.message))
  168.  
  169. }
  170.  
  171. handleStringChange = (name: string) =>(event:SyntheticEvent<HTMLInputElement>)=>{
  172. this.setState({
  173. // $FlowFixMe
  174. [name]:event.target.value,
  175. })
  176. };
  177.  
  178. handleNumberChange = (value: number) =>(event:SyntheticEvent<HTMLInputElement>)=>{
  179. this.setState({
  180. // $FlowFixMe
  181. [value]:event.target.value,
  182. })
  183. };
  184.  
  185. /*;*/
  186. /*;*/
  187.  
  188. /*let optionTemplate = this.state.values.map(v => {
  189. var data = {label: v.name, countyId: v.countyId}
  190. return( <Select
  191. placeholder={"Hjemmekommune"}
  192. name="colors"
  193. options={optiontem}
  194. className="basic-multi-select"
  195. classNamePrefix="select"
  196. />)})*/
  197. render(){
  198. let optionTemplate = this.state.values.map(v => {
  199. const data = {label: v.name, value: v.countyId, countyId: v.countyId};
  200. return(data)
  201. });
  202. return(
  203. <Grid>
  204. <Col md={3}></Col>
  205. <Col md={6}>
  206. <Form horizontal>
  207. <FormGroup controlId="formHorizontalEmail">
  208. <FormGroup>
  209. <FormGroup>
  210. <Col md={3}></Col>
  211. <Col md={6}>
  212. <PageHeader>
  213. Registrer bruker
  214. </PageHeader>
  215. </Col>
  216. <Col md={3}></Col>
  217. </FormGroup>
  218. <Col md={6}>
  219. <FormGroup>
  220. <FormControl type="text" value={this.state.firstName} placeholder="Fornavn"
  221. onChange={this.handleStringChange("firstName")}
  222. />
  223. </FormGroup>
  224. </Col>
  225. <Col md={6}>
  226. <FormGroup>
  227. <FormControl type="text" value={this.state.lastName} placeholder="Etternavn"
  228. onChange={this.handleStringChange("lastName")}/>
  229. </FormGroup>
  230. </Col>
  231. <Col md={6}>
  232. <FormGroup>
  233. <FormControl type="number" value={this.state.phone} placeholder="Telefonnummer"
  234. onChange={this.handleStringChange("phone")}
  235. />
  236. </FormGroup>
  237. </Col>
  238. <Col md={6}>
  239. <FormGroup>
  240. <FormControl type="text" value={this.state.mail} placeholder="Epost"
  241. onChange={this.handleStringChange("mail")}/>
  242. </FormGroup>
  243. </Col>
  244. <Col md={6}>
  245. <FormGroup>
  246. <FormControl type="password" value={this.state.password} placeholder="Passord"
  247. onChange={this.handleStringChange("password")}
  248. />
  249. </FormGroup>
  250. </Col>
  251. <Col md={6}>
  252. <FormGroup>
  253. <FormControl type="password" value={this.state.password2} placeholder="Gjenta passord"
  254. onChange={this.handleStringChange("password2")}/>
  255. </FormGroup>
  256. </Col>
  257. </FormGroup>
  258. <FormGroup>
  259. <Col md={4}>
  260. <FormGroup>
  261. <Label>
  262. Hjemmekommune
  263. </Label>
  264. </FormGroup>
  265. <FormGroup>
  266. <Select
  267. placeholder={"Hjemmekommune"}
  268. name="colors"
  269. options={optionTemplate}
  270. className="basic-multi-select"
  271. classNamePrefix="select"
  272. onChange={this.handleChangeCounty}
  273. />
  274. </FormGroup>
  275. </Col>
  276. <Col md={4}>
  277. <FormGroup>
  278. <Label>Velg kommuner du vil følge</Label>
  279. </FormGroup>
  280. <FormGroup>
  281. <Checkbox inline>Oslo</Checkbox><Checkbox>Trondheim</Checkbox><Checkbox>Bergen</Checkbox>
  282. </FormGroup>
  283. </Col>
  284. <Col md={4}>
  285. <FormGroup>
  286. <Label>Velg arbeidsområder</Label>
  287. </FormGroup>
  288. <FormGroup>
  289. <Checkbox inline>Vann og avløp</Checkbox><Checkbox>Veiarbeid</Checkbox><Checkbox>Strømbrudd</Checkbox>
  290. </FormGroup>
  291. </Col>
  292. </FormGroup>
  293. <FormGroup>
  294. <Col md={4}/>
  295. <Col md ={4}>
  296. <Button type="button" onClick={this.checkMail}>Registrer</Button>
  297. </Col>
  298. <Col md={4}>
  299. </Col>
  300. </FormGroup>
  301. </FormGroup>
  302. </Form>
  303. </Col>
  304. <Col md={3}></Col>
  305. </Grid>
  306. );
  307. }
  308. checkMail = () =>{
  309. var validator = require("email-validator");
  310.  
  311. if(!(validator.validate(this.state.mail))){
  312. Alert.warning("Eposten eksisterer ikke")
  313. }else{
  314. this.register();
  315. }
  316. }
  317.  
  318. checkPass = () => {
  319.  
  320. if (this.state.password !== this.state.password2) {
  321. console.log("To ulike passord");
  322. Alert.warning("Du skrev to ulike passord");
  323. }
  324. else {
  325. let decimal = /^(?=.*\d)(?=.*[a-z])(?=.*[A-Z])(?=.*[^a-zA-Z0-9])(?!.*\s).{8,15}$/;
  326. if(this.state.password.match(decimal))
  327. {
  328. this.register();
  329. }
  330. else
  331. {
  332. Alert.warning('Password has to be between 8 to 15 characters which contain at least one lowercase letter, one uppercase letter, one numeric digit, and one special character')
  333. }
  334. }
  335.  
  336. }
  337.  
  338.  
  339.  
  340.  
  341. register = () => {
  342. console.log("test", this.state);
  343.  
  344. const newUser = {
  345. mail: this.state.mail,
  346. firstName: this.state.firstName,
  347. lastName: this.state.lastName,
  348. password: this.state.password,
  349. phone: this.state.phone,
  350. countyId: this.state.choosen,
  351. };
  352.  
  353. console.log("county", this.state.choosen)
  354. userService
  355. .addUser(newUser)
  356. .then(user =>(this.state = user)).then(Alert.success("Bruker registrert"))
  357. .catch((error: Error)=>Alert.danger(error.message))
  358. }
  359. }
  360. /*
  361. * <DropdownButton title="Hjemmekommune">
  362. value={this.state.countyName}
  363. onChange={(e)=>this.handleChangeCounty(e)}>
  364. {this.state.countyName.map((r, i) => {
  365. return <option key={i} value={r}>{r}
  366. </option>
  367. })
  368. }
  369.  
  370. </DropdownButton>
  371.  
  372. checkPass(){
  373. console.log(state);
  374. if(this.state.password==this.state.password2){
  375. this.register();
  376. Alert.success();
  377. }else{
  378. Alert.warning();
  379. }
  380. }
  381.  
  382.  
  383. */
  384.  
  385. import {CountyService, UserService} from "../../services";
  386. import {Component} from 'react';
  387. import * as React from 'react';
  388. import {Alert} from "../../widgets";
  389. import ReactDOM from 'react-dom';
  390. import {County} from "../../classTypes";
  391. import DropdownButton from "react-bootstrap/es/DropdownButton";
  392. import MenuItem from "react-bootstrap/es/MenuItem";
  393. import Row from "react-bootstrap/es/Row";
  394. import Col from "react-bootstrap/es/Col";
  395. import Button from "react-bootstrap/es/Button";
  396. import FormGroup from "react-bootstrap/es/FormGroup";
  397. import {Form, FormControl, Label, PageHeader} from 'react-bootstrap';
  398. import ControlLabel from "react-bootstrap/es/ControlLabel";
  399. import Grid from "react-bootstrap/es/Grid";
  400. import Checkbox from "react-bootstrap/es/Checkbox";
  401. import Select from "react-select";
  402.  
  403. let countyService = new CountyService();
  404. let userService = new UserService();
  405.  
  406. /*interface State{
  407. companyName: string;
  408. category: Array<Object>;
  409. mail: string;
  410. firstName: string;
  411. lastName: string;
  412. address: string;
  413. postNumber: string;
  414. password: string;
  415. password2: string;
  416. typeName: string;
  417. phone: string;
  418. points: number;
  419. countyId: number;
  420. countyName: string;
  421. description: string;
  422. orgNumber: number;
  423. active: number;
  424. isLoaded: boolean;
  425. }
  426. interface Props{
  427. match: Object,
  428. }*/
  429. export class RegisterCompany extends Component<Props, State>{
  430.  
  431. constructor(props) {
  432. super(props);
  433. this.state = {
  434. companyName: "",
  435. category: [],
  436. mail: "",
  437. firstName: "",
  438. lastName: "",
  439. address: "",
  440. postNumber: "",
  441. password: "",
  442. password2: "",
  443. typeName: "",
  444. phone: "",
  445. points: 0,
  446. active: 0,
  447. isLoaded: false,
  448. choosen: {name: "Bergen", countyId: 1},
  449. values:[
  450. {name: "Bergen", countyId: 1}
  451. //{ name: this.county.name, countyId: this.county.countyId}
  452. ],
  453. description: "",
  454. orgNumber: ""
  455. };
  456.  
  457. this.handleChangeCounty = this.handleChangeCounty.bind(this)
  458. }
  459.  
  460.  
  461. handleChangeCounty(e: Object){
  462. this.setState({
  463. choosen: JSON.parse(e.value)
  464. })
  465. };
  466.  
  467.  
  468. componentWillMount() {
  469. var arr = [];
  470. countyService
  471. .getCounties()
  472. .then(county2 => {
  473. county2.map(e => {
  474. var elem = {
  475. name: e.name,
  476. countyId: e.countyId
  477. };
  478. arr = arr.concat(elem)
  479.  
  480. });
  481. this.setState({
  482. values: arr
  483. })
  484. })
  485.  
  486.  
  487. //this.state.countyName.push(this.state.county.name)})
  488. .catch((error: Error)=>Alert.danger(error.message))
  489.  
  490. }
  491.  
  492. handleStringChange = (name: string) =>(event:SyntheticEvent<HTMLInputElement>)=>{
  493. this.setState({
  494. // $FlowFixMe
  495. [name]:event.target.value,
  496. })
  497. };
  498.  
  499. handleNumberChange = (value: number) =>(event:SyntheticEvent<HTMLInputElement>)=>{
  500. this.setState({
  501. // $FlowFixMe
  502. [value]:event.target.value,
  503. })
  504. };
  505.  
  506.  
  507.  
  508. render(){
  509. let optionTemplate = this.state.values.map(v => {
  510. const data = {label: v.name, value: v.countyId, countyId: v.countyId};
  511. return(data)
  512. });
  513. return(
  514. <Grid>
  515. <Col md={3}></Col>
  516. <Col md={6}>
  517. <Form horizontal>
  518.  
  519. <FormGroup controlId="formHorizontalEmail">
  520. <FormGroup>
  521. <Col md={3}></Col>
  522. <Col md={6}>
  523. <PageHeader>
  524. Registrer bedrift
  525. </PageHeader>
  526. </Col>
  527. <Col md={3}></Col>
  528. </FormGroup>
  529. <FormGroup>
  530. <Col md={6}>
  531. <FormGroup>
  532. <FormControl type="text" value={this.state.firstName} placeholder="Fornavn"
  533. onChange={this.handleStringChange("firstName")}
  534. />
  535. </FormGroup>
  536. </Col>
  537. <Col md={6}>
  538. <FormGroup>
  539. <FormControl type="text" value={this.state.lastName} placeholder="Etternavn"
  540. onChange={this.handleStringChange("lastName")}/>
  541. </FormGroup>
  542. </Col>
  543. </FormGroup>
  544. <FormGroup>
  545. <Col md={6}>
  546. <FormGroup>
  547. <FormControl type="text" value={this.state.address} placeholder="Addresse"
  548. onChange={this.handleStringChange("address")}
  549. />
  550. </FormGroup>
  551. </Col>
  552. <Col md={6}>
  553. <FormGroup>
  554. <FormControl type="number" value={this.state.postNumber} placeholder="Postnummer"
  555. onChange={this.handleNumberChange("postNumber")}/>
  556. </FormGroup>
  557. </Col>
  558. </FormGroup>
  559. <FormGroup>
  560. <Col md={6}>
  561. <FormGroup>
  562. <FormControl type="text" value={this.state.companyName} placeholder="Bedriftens navn"
  563. onChange={this.handleStringChange("companyName")}
  564. />
  565. </FormGroup>
  566. </Col>
  567. {' '}
  568. <Col md={6}>
  569. <FormGroup>
  570. <FormControl type="number" value={this.state.phone} placeholder="Telefonnummer"
  571. onChange={this.handleStringChange("phone")}
  572. />
  573. </FormGroup>
  574. </Col>
  575. </FormGroup>
  576. <FormGroup>
  577. <Col md={6}>
  578. <FormGroup>
  579. <FormControl type="text" value={this.state.mail} placeholder="Epost"
  580. onChange={this.handleStringChange("mail")}/>
  581. </FormGroup>
  582. </Col>
  583. <Col md={6}>
  584. <FormGroup>
  585. <FormControl type="text" value={this.state.mail} placeholder="Organisasjonsnummer"
  586. onChange={this.handleStringChange("orgNumber")}/>
  587. </FormGroup>
  588. </Col>
  589. </FormGroup>
  590. <FormGroup>
  591. <Col md={6}>
  592. <FormGroup>
  593. <FormControl type="password" value={this.state.password} placeholder="Passord"
  594. onChange={this.handleStringChange("password")}
  595. />
  596. </FormGroup>
  597. </Col>
  598. <Col md={6}>
  599. <FormGroup>
  600. <FormControl type="password" value={this.state.password2} placeholder="Gjenta passord"
  601. onChange={this.handleStringChange("password2")}/>
  602. </FormGroup>
  603. </Col>
  604. </FormGroup>
  605. <FormGroup>
  606. <Col md={4}>
  607. <FormGroup>
  608. <Label>
  609. Hjemmekommune
  610. </Label>
  611. </FormGroup>
  612. <FormGroup>
  613. <Select
  614. placeholder={"Hjemmekommune"}
  615. name="colors"
  616. options={optionTemplate}
  617. className="basic-multi-select"
  618. classNamePrefix="select"
  619. onChange={this.handleChangeCounty}
  620. />
  621. </FormGroup>
  622. </Col>
  623. <Col md={4}>
  624. <FormGroup>
  625. <Select
  626. placeholder={"Kommuner å følge"}
  627. isMulti
  628. name="colors"
  629. options={optionTemplate}
  630. className="basic-multi-select"
  631. classNamePrefix="select"
  632. />
  633. </FormGroup>
  634. </Col>
  635. <Col md={4}> /*Ikke gjør noe med det her enda, vi kan vente å se hvor god tid vi får*/
  636. <FormGroup>
  637. <Label>Velg arbeidsområder</Label>
  638. </FormGroup>
  639. <FormGroup>
  640. <Checkbox inline>Vann og avløp</Checkbox><Checkbox>Veiarbeid</Checkbox><Checkbox>Strømbrudd</Checkbox>
  641. </FormGroup>
  642. </Col>
  643. </FormGroup>
  644. <FormGroup>
  645. <Col md={4}/>
  646. <Col md ={4}>
  647. <Button type="button" onClick={this.checkMail}>Registrer</Button>
  648. </Col>
  649. <Col md={4}>
  650. </Col>
  651. </FormGroup>
  652. </FormGroup>
  653. </Form>
  654. </Col>
  655. <Col md={3}></Col>
  656. </Grid>
  657. );
  658. }
  659. checkMail = () =>{
  660. var validator = require("email-validator");
  661.  
  662. if(!(validator.validate(this.state.mail))){
  663. Alert.warning("Eposten eksisterer ikke")
  664. }else{
  665. this.register();
  666. }
  667. }
  668.  
  669. checkPass = () => {
  670.  
  671. if (this.state.password !== this.state.password2) {
  672. console.log("To ulike passord");
  673. Alert.warning("Du skrev to ulike passord");
  674. }
  675. else {
  676. let decimal = /^(?=.*\d)(?=.*[a-z])(?=.*[A-Z])(?=.*[^a-zA-Z0-9])(?!.*\s).{8,15}$/;
  677. if(this.state.password.match(decimal))
  678. {
  679. this.register();
  680. }
  681. else
  682. {
  683. Alert.warning('Password has to be between 8 to 15 characters which contain at least one lowercase letter, one uppercase letter, one numeric digit, and one special character')
  684. }
  685. }
  686.  
  687. }
  688.  
  689.  
  690.  
  691.  
  692. register = () => {
  693. console.log("test", this.state);
  694. var mail = this.state.mail
  695. var firstName = this.state.firstName
  696. var lastName = this.state.lastName
  697. var password = this.state.password
  698. var phone = this.state.phone
  699. var countyId = this.state.choosen.countyId
  700. console.log("county", countyId)
  701. userService
  702. .addUser(this.state.mail, this.state.firstName, this.state.lastName, this.state.password, this.state.phone, this.state.choosen.countyId)
  703. .then(user =>(this.state = user)).then(Alert.success("Bruker registrert"))
  704. .catch((error: Error)=>Alert.danger(error.message))
  705. };
  706. }
  707.  
  708. /*{' '}
  709. <FormGroup>
  710. <Col>
  711. <Input type="text" value={this.state.lastName} placeholder="Etternavn"
  712. onChange={this.handleStringChange("lastName")}
  713. />
  714. </Col>
  715. </FormGroup>
  716. {' '}
  717. </Row>
  718. <Row>
  719. <FormGroup>
  720. <Col>
  721. <Input type="text" value={this.state.phone} placeholder="Telefonnummer"
  722. onChange={this.handleNumberChange("phone")}
  723. />
  724. </Col>
  725. </FormGroup>
  726. </Row>
  727. <Row>
  728. <FormGroup>
  729. <Col>
  730. <label>
  731. Velg Kommune:
  732. <select value={this.state.values.countyId} onChange={this.handleChangeCounty}>
  733. {optionTemplate}
  734. </select>
  735. </label>
  736. </Col>
  737. </FormGroup>
  738. </Row>
  739. <Row>
  740. <FormGroup>
  741. <Col sm="12">
  742. <Input type="text" value={this.state.mail} placeholder="Epost"
  743. onChange={this.handleStringChange("mail")}
  744. />
  745. </Col>
  746. </FormGroup>
  747. </Row>
  748. <Row>
  749. <FormGroup>
  750. <Col>
  751. <Input type="text" value={this.state.password} placeholder="Passord"
  752. onChange={this.handleStringChange("password")}
  753. />
  754. </Col>
  755. </FormGroup>
  756. {' '}
  757. <FormGroup>
  758. <Col>
  759. <Input type="text" value={this.state.password2} placeholder="Gjenta passord"
  760. onChange={this.handleStringChange("password2")}
  761. />
  762. </Col>
  763. </FormGroup>
  764. {' '}
  765. </Row>*/
  766.  
  767. // @flow
  768. import axios from 'axios';
  769. import {User, Issue, Category, Category2, Category3, Company, Event, Type, County} from "./classTypes";
  770.  
  771. axios.interceptors.response.use(response => response.data);
  772.  
  773.  
  774.  
  775. export class UserService {
  776.  
  777. addUser(newUser: User): Promise<Response> {
  778. return axios.post('/add_user', newUser);
  779. }//end method
  780.  
  781. getUserLogin(email: string): Promise<string[]>{
  782. return axios.get('/verify_user/' + email);
  783. }//end method
  784.  
  785. getUser(mail: string): Promise<User>{
  786. return axios.get('/user/get_user/' + mail);
  787. }//end method
  788.  
  789. login(userMail: Object<JSON>): Promise<void>{
  790. return axios.post('/login/', userMail);
  791. }//end method
  792.  
  793. getMyIssues(userMail: string): Promise<JSON>{
  794. return axios.get('/user/getMyIssues/' + userMail);
  795. }//end method
  796.  
  797. }//end class
  798.  
  799. export class CategoryService {
  800.  
  801. getCategory1(): Promise<Category[]> {
  802. return axios.get('/get_category1');
  803. }
  804.  
  805. getCategory2(): Promise<Category2[]>{
  806. return axios.get('/get_category2');
  807. }
  808.  
  809. getCategory3(): Promise<Category3[]>{
  810. return axios.get('/get_category3');
  811. }
  812. }
  813.  
  814. export class CountyService{
  815. getCounties(): Promise<County[]>{
  816. return axios.get('/getCounties');
  817. }
  818. }
  819.  
  820. export class MyPage{
  821.  
  822.  
  823.  
  824. }
  825.  
  826. export function getAllCounties(usermail:string): Promise<County[]> {
  827. return axios.get('/getAllCountiesMinusUsers/'+ usermail);
  828. }
  829.  
  830. export function getUsersCounties(usermail: string): Promise<County[]>{
  831. return axios.get('/getSubscribedCounties/'+ usermail);
  832. }
  833.  
  834. export function deleteSubscription(usermail: string){
  835. return axios.delete('/deleteAllSubscribedCounties/'+ usermail);
  836. }
  837.  
  838. export function addSubscription(json: Object){
  839. return axios.post('/addSubscription', json);
  840. }
  841. // @flow
  842.  
  843. import {Dao} from "../dao";
  844.  
  845. const bcrypt = require('bcrypt-nodejs'); //to hash password
  846.  
  847. export class UserDao extends Dao {
  848.  
  849. addUser(json: Object,hashed:string, callback: Function) {
  850. let val = [json.mail, json.firstName, json.lastName, hashed, json.phone, json.countyId];
  851. super.query(
  852. "insert into user (mail, firstName, lastName, password, typeName, phone, points, countyId, active) values(?, ?, ?, ?, 'Private', ?, 0, ?, 1)",
  853. val,
  854. callback);
  855. }//end method
  856.  
  857. getUserLogin(userMail: string, callback: Function) {
  858. super.query("select mail, password, typeName from user where mail=? ", [userMail], callback);
  859. }//end method
  860.  
  861. getUser(userMail: string, callback: Function) {
  862. super.query("select * from user where mail=? ", [userMail], callback);
  863. }//end method}
  864.  
  865. getIssuesForOneUser(userMail: string, callback: Function){
  866. super.query("select categoryId, issues.active, issueId, userMail, latitude, longitude, text, pic, " +
  867. "date, statusName, countyId, name as 'category', priority from issues " +
  868. "natural join category where userMail='per@usermail.com' and active=1", [userMail], callback);
  869. }//end method
  870. }
  871.  
  872. // @flow
  873.  
  874. export class User {
  875. mail: string;
  876. firstName: string;
  877. lastName: string;
  878. password: string;
  879. typeName: string;
  880. phone: string;
  881. points: number;
  882. countyId: number;
  883. active: number;
  884.  
  885. constructor(mail: string, firstName: string, lastName: string, typeName: string, phone: string, points: number, countyId: number, active: number) {
  886. this.mail = mail;
  887. this.firstName = firstName;
  888. this.lastName = lastName;
  889. this.typeName = typeName;
  890. this.phone = phone;
  891. this.points = points;
  892. this.countyId = countyId;
  893. this.active = active;
  894. }
  895. }
  896.  
  897. export class Issue {
  898. issueId: number;
  899. userMail: string;
  900. latitude: number;
  901. longitude: number;
  902. text: string;
  903. pic: string;
  904. date: string;
  905. statusName: string;
  906. categoryId: number;
  907. countyId: number;
  908.  
  909. constructor(issueId: number, userMail: string, latitude: number, longitude: number, text: string, pic: string, date: string, statusName: string, categoryId: number, countyId: number, active: number) {
  910. this.issueId = issueId;
  911. this.userMail = userMail;
  912. this.latitude = latitude;
  913. this.longitude = longitude;
  914. this.text = text;
  915. this.pic = pic;
  916. this.date = date;
  917. this.statusName = statusName;
  918. this.categoryId = categoryId;
  919. this.countyId = countyId;
  920. this.active = active;
  921. }
  922.  
  923. }
  924.  
  925. export class Type {
  926. typeName: string;
  927. active: number;
  928.  
  929. constructor(typeName: string, active: number) {
  930. this.typeName = typeName;
  931. this.active = active;
  932. }
  933. }
  934.  
  935. export class Company extends Type {
  936. companyMail: string;
  937. companyName: string;
  938. description: string;
  939.  
  940. constructor(
  941. typeName: string,
  942. active: number,
  943. companyMail: string,
  944. companyName: string,
  945. description: string
  946. ) {
  947. super(typeName, active);
  948. this.companyMail = companyMail;
  949. this.companyName = companyName;
  950. this.description = description;
  951. }
  952. }
  953.  
  954. export class Category {
  955. categoryId: number;
  956. name: string;
  957. priority: number;
  958. active: number;
  959.  
  960. constructor(
  961. categoryId: number,
  962. name: string,
  963. priority: number,
  964. active: number
  965. ) {
  966. this.categoryId = categoryId;
  967. this.name = name;
  968. this.priority = priority;
  969. this.active = active;
  970. }
  971. }
  972.  
  973. export class Category2 extends Category {
  974. category2Id: number;
  975.  
  976. constructor(categoryId: number, category2Id: number, name: string, priority: number, active: number) {
  977.  
  978. // noinspection JSAnnotator
  979. this.category2Id = categoryId;
  980.  
  981. super(category2Id, name, priority, active);
  982. }
  983. }
  984.  
  985. export class Category3 extends Category {
  986. category2Id: number;
  987.  
  988. constructor(categoryId2: number, categoryId3: number, name: string, priority: number, active: number) {
  989.  
  990. // noinspection JSAnnotator
  991. this.category2Id = categoryId2;
  992.  
  993. super(categoryId3, name, priority, active);
  994. }
  995. }
  996.  
  997. export class Event {
  998. eventId: number;
  999. title: string;
  1000. text: string;
  1001. date: string;
  1002. userMail: string;
  1003. active: number;
  1004.  
  1005. constructor(
  1006. eventId: number,
  1007. title: string,
  1008. text: string,
  1009. date: string,
  1010. userMail: string,
  1011. active: number
  1012. ) {
  1013. this.eventId = eventId;
  1014. this.title = title;
  1015. this.text = text;
  1016. this.date = date;
  1017. this.userMail = userMail;
  1018. this.active = active;
  1019. }
  1020. }
  1021.  
  1022. export class Status{
  1023. progressBar: String;
  1024. progress: number;
  1025.  
  1026.  
  1027. constructor(status: string){
  1028. //if issue is registered
  1029. if(status === 'Registered'){
  1030. this.progressBar= "info";
  1031. this.progress = 100;
  1032.  
  1033. //if issue is under processing
  1034. }else if(status === 'In progress'){
  1035. this.progressBar ="warning";
  1036. this.progress = 50;
  1037. //if issue is resolved
  1038. }else{
  1039. this.progressBar = "success";
  1040. this.progress = 100;
  1041. }//end condition
  1042. }//end constructor
  1043. }/
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement