Code Monkey home page Code Monkey logo

dsi-mpractice-2's Introduction

DSI Practice 2

W3C Validation GitHub top language GitHub repo size

GRAPHICAL INTERFACE OPERATION

  • The screen shows a list of cars and, for each one, displays different information fields.
  • If the user types something in the FILTER field, only the vehicles whose Make begins with the characters typed by the user will be displayed. So, in the example, if the user types "R" only Renault vehicles will be shown.
  • If we click on REDUCE the price of the vehicle will be multiplied by 0.90.
  • If we click on SOLD the vehicle will disappear from the list.
  • The PVP is the Price x 1,21.
  • If the condition of the vehicle is GOOD, the price will be displayed in GREEN background. Otherwise, in RED.

INSTRUCTIONS TO DEAL WITH THE MICROPRACTICE

  • Create a new Angular application (in local repository on your PC):

    • ng new micropractice02
  • The data model, this time, we are going to store it in a custom CLASS called Car. This class will be defined in a file called: coche.ts.

To create it: ng g class car

  • Car fields:

    • make, model and picture (can be ="") → string type.
    • model_date and sale_date → date.
    • price → number
    • status → car_status
    • getPVP():number → return price * 1,21
    • enum CarStatus {GOOD, BAD}
  • Working with PIPEs:

    • Make will always be presented in CAPITALS.
    • Model will always be in MINUSCRIPLES.
    • Year (only the YEAR of the date of purchase shall be presented).
    • On sale since (present MONTH and YEAR of the date it was put on sale).
    • Price and RRP shall be presented without decimals, and with "," for thousands. Followed by €.
  • Working with Angular directives: ngIf, ngClass and ngFor.

    • If car.photo=='' → present text: (no photo!)
    • If car.state==CarState.GOOD → green background (this is done with ngClass).

TIP

  • To implement FILTERING you can do it in different ways. An easy one, is to create a function that returns a list of IDs (numbers, car indexes in the car list) that meet the condition that their Make field starts with the substring typed by the user in Filter.
  • So, the TEMPLATE would look like this: <tr *ngFor='let id of getFiltered();'> and, we would access each element like this: {{cars[id].brand}}, etc....
  • In this way, we would have available to process the SOLD and REDUCE buttons, the ID field that is the index of the total cars list (without filtering). This can be very useful to know which one to delete or downgrade.

MODEL INITIALIZATION

At least two variables must be defined in the model:

public EstadoCoche:any = EstadoCoche; // THIS LINE ONLY SERVES SO WE CAN USE EstadoCoche in the TEMPLATE.

public cars:Array=[ new Car('renault','scenic',new Date(2007,10,1),new Date(2018,3,1),5000,'car01.jpg',CarStatus.GOOD), new Car('renault','scenic',new Date(2007,10,1),new Date(2018,3,1),5000,'car01. jpg',CarStatus.GOOD), new Car('renault','scenic',new Date(2007,10,1),new Date(2018,3,1),5000,'car01.jpg',CarStatus.GOOD)]

An array of type Car is defined, with values entered "hard code".

Deploy in GitHub Pages

No need to create the branch, it creates itself.

Once the repository is created with everything in GitHub.

ng add angular-cli-ghpages
ng deploy --base-href=/<repositoryname>/

dsi-mpractice-2's People

Contributors

xvenve avatar dependabot[bot] avatar carloscro avatar raulgimenezdd avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.