Adds vuejs with vue-cli, adds cors fairing to rocket
This commit is contained in:
20
.gitignore
vendored
20
.gitignore
vendored
@@ -16,3 +16,23 @@
|
|||||||
# Node.js
|
# Node.js
|
||||||
**/node_modules
|
**/node_modules
|
||||||
**/package-lock.json
|
**/package-lock.json
|
||||||
|
**/.DS_Store
|
||||||
|
**/dist
|
||||||
|
|
||||||
|
# local env files
|
||||||
|
.env.local
|
||||||
|
.env.*.local
|
||||||
|
|
||||||
|
# Log files
|
||||||
|
npm-debug.log*
|
||||||
|
yarn-debug.log*
|
||||||
|
yarn-error.log*
|
||||||
|
|
||||||
|
# Editor directories and files
|
||||||
|
.idea
|
||||||
|
.vscode
|
||||||
|
*.suo
|
||||||
|
*.ntvs*
|
||||||
|
*.njsproj
|
||||||
|
*.sln
|
||||||
|
*.sw*
|
||||||
|
|||||||
@@ -11,16 +11,31 @@ use self::planner::solver::{Variables, Domain, Problem};
|
|||||||
/// Breakfast => RecipeCategory::Breakfast
|
/// Breakfast => RecipeCategory::Breakfast
|
||||||
/// Lunch => RecipeCategory::MainCourse
|
/// Lunch => RecipeCategory::MainCourse
|
||||||
/// Dinner => RecipeCategory::MainCourse
|
/// Dinner => RecipeCategory::MainCourse
|
||||||
type Day = String;
|
|
||||||
const DAYS: &[&str] = &["Lundi", "Mardi", "Mercredi"];
|
|
||||||
|
|
||||||
#[allow(dead_code)]
|
mod template {
|
||||||
enum Meals {
|
//! Exports the [`Template`] struct.
|
||||||
Breakfast(Day),
|
|
||||||
Lunch(Day),
|
type Day = String;
|
||||||
Dinner(Day)
|
const DAYS: &[&str] = &["Lundi", "Mardi", "Mercredi"];
|
||||||
|
|
||||||
|
#[allow(dead_code)]
|
||||||
|
enum Meals {
|
||||||
|
Breakfast(Day),
|
||||||
|
Lunch(Day),
|
||||||
|
Dinner(Day)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub struct Template;
|
||||||
|
|
||||||
|
impl Template {
|
||||||
|
fn empty() {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
impl Into<String> for Meals {
|
impl Into<String> for Meals {
|
||||||
fn into(self) -> String {
|
fn into(self) -> String {
|
||||||
match self {
|
match self {
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ type Domains<'a, V> = HashMap<String, &'a Domain<V>>;
|
|||||||
/// The domain of values that can be assigned to variables
|
/// The domain of values that can be assigned to variables
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
pub struct Domain<V> {
|
pub struct Domain<V> {
|
||||||
pub values: Vec<V>
|
values: Vec<V>
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<V> Domain<V> {
|
impl<V> Domain<V> {
|
||||||
@@ -26,6 +26,9 @@ impl<V> Domain<V> {
|
|||||||
Domain { values }
|
Domain { values }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn values(&self) -> &Vec<V> {
|
||||||
|
&self.values
|
||||||
|
}
|
||||||
/// Returns a new domain with the given filter applied to inner values
|
/// Returns a new domain with the given filter applied to inner values
|
||||||
///
|
///
|
||||||
/// # Examples
|
/// # Examples
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ edition = "2018"
|
|||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
rocket = "0.4.0"
|
rocket = "0.4.0"
|
||||||
|
rocket_cors = { git = "https://github.com/lawliet89/rocket_cors", branch = "master" }
|
||||||
cookbook = { path = "../cookbook/" }
|
cookbook = { path = "../cookbook/" }
|
||||||
serde = "1.0"
|
serde = "1.0"
|
||||||
serde_derive = "1.0"
|
serde_derive = "1.0"
|
||||||
|
|||||||
@@ -3,11 +3,15 @@
|
|||||||
#[macro_use] extern crate rocket;
|
#[macro_use] extern crate rocket;
|
||||||
#[macro_use] extern crate rocket_contrib;
|
#[macro_use] extern crate rocket_contrib;
|
||||||
#[macro_use] extern crate serde_derive;
|
#[macro_use] extern crate serde_derive;
|
||||||
|
extern crate rocket_cors;
|
||||||
extern crate cookbook;
|
extern crate cookbook;
|
||||||
|
|
||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
use rocket::response::{NamedFile, status::NotFound};
|
use rocket::{
|
||||||
|
response::{NamedFile, status::NotFound},
|
||||||
|
http::Method,
|
||||||
|
};
|
||||||
|
use rocket_cors::{AllowedHeaders, AllowedOrigins, Error};
|
||||||
|
|
||||||
#[get("/")]
|
#[get("/")]
|
||||||
fn index() -> Result<NamedFile, NotFound<String>> {
|
fn index() -> Result<NamedFile, NotFound<String>> {
|
||||||
@@ -66,9 +70,25 @@ mod api {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn main() {
|
fn main() -> Result<(), Error> {
|
||||||
|
let (allowed_origins, failed_origins) = AllowedOrigins::some(&["http://localhost:8080"]);
|
||||||
|
assert!(failed_origins.is_empty());
|
||||||
|
|
||||||
|
// You can also deserialize this
|
||||||
|
let cors = rocket_cors::CorsOptions {
|
||||||
|
allowed_origins: allowed_origins,
|
||||||
|
allowed_methods: vec![Method::Get].into_iter().map(From::from).collect(),
|
||||||
|
allowed_headers: AllowedHeaders::some(&["Authorization", "Accept"]),
|
||||||
|
allow_credentials: true,
|
||||||
|
..Default::default()
|
||||||
|
}
|
||||||
|
.to_cors()?;
|
||||||
|
|
||||||
rocket::ignite()
|
rocket::ignite()
|
||||||
.attach(api::CookbookDbConn::fairing())
|
.attach(api::CookbookDbConn::fairing())
|
||||||
.mount("/", routes![index])
|
.mount("/", routes![index])
|
||||||
.mount("/api", routes![api::recipes_list, api::delete_recipe]).launch();
|
.mount("/api", routes![api::recipes_list, api::delete_recipe])
|
||||||
|
.attach(cors)
|
||||||
|
.launch();
|
||||||
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|||||||
29
web/vue/README.md
Normal file
29
web/vue/README.md
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
# vue
|
||||||
|
|
||||||
|
## Project setup
|
||||||
|
```
|
||||||
|
npm install
|
||||||
|
```
|
||||||
|
|
||||||
|
### Compiles and hot-reloads for development
|
||||||
|
```
|
||||||
|
npm run serve
|
||||||
|
```
|
||||||
|
|
||||||
|
### Compiles and minifies for production
|
||||||
|
```
|
||||||
|
npm run build
|
||||||
|
```
|
||||||
|
|
||||||
|
### Run your tests
|
||||||
|
```
|
||||||
|
npm run test
|
||||||
|
```
|
||||||
|
|
||||||
|
### Lints and fixes files
|
||||||
|
```
|
||||||
|
npm run lint
|
||||||
|
```
|
||||||
|
|
||||||
|
### Customize configuration
|
||||||
|
See [Configuration Reference](https://cli.vuejs.org/config/).
|
||||||
5
web/vue/babel.config.js
Normal file
5
web/vue/babel.config.js
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
module.exports = {
|
||||||
|
presets: [
|
||||||
|
'@vue/app'
|
||||||
|
]
|
||||||
|
}
|
||||||
46
web/vue/package.json
Normal file
46
web/vue/package.json
Normal file
@@ -0,0 +1,46 @@
|
|||||||
|
{
|
||||||
|
"name": "vue",
|
||||||
|
"version": "0.1.0",
|
||||||
|
"private": true,
|
||||||
|
"scripts": {
|
||||||
|
"serve": "vue-cli-service serve",
|
||||||
|
"build": "vue-cli-service build",
|
||||||
|
"lint": "vue-cli-service lint"
|
||||||
|
},
|
||||||
|
"dependencies": {
|
||||||
|
"vue": "^2.5.22"
|
||||||
|
},
|
||||||
|
"devDependencies": {
|
||||||
|
"@vue/cli-plugin-babel": "^3.4.0",
|
||||||
|
"@vue/cli-plugin-eslint": "^3.4.0",
|
||||||
|
"@vue/cli-service": "^3.4.0",
|
||||||
|
"babel-eslint": "^10.0.1",
|
||||||
|
"eslint": "^5.8.0",
|
||||||
|
"eslint-plugin-vue": "^5.0.0",
|
||||||
|
"vue-template-compiler": "^2.5.21"
|
||||||
|
},
|
||||||
|
"eslintConfig": {
|
||||||
|
"root": true,
|
||||||
|
"env": {
|
||||||
|
"node": true
|
||||||
|
},
|
||||||
|
"extends": [
|
||||||
|
"plugin:vue/essential",
|
||||||
|
"eslint:recommended"
|
||||||
|
],
|
||||||
|
"rules": {},
|
||||||
|
"parserOptions": {
|
||||||
|
"parser": "babel-eslint"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"postcss": {
|
||||||
|
"plugins": {
|
||||||
|
"autoprefixer": {}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"browserslist": [
|
||||||
|
"> 1%",
|
||||||
|
"last 2 versions",
|
||||||
|
"not ie <= 8"
|
||||||
|
]
|
||||||
|
}
|
||||||
BIN
web/vue/public/favicon.ico
Normal file
BIN
web/vue/public/favicon.ico
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 1.1 KiB |
17
web/vue/public/index.html
Normal file
17
web/vue/public/index.html
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<meta charset="utf-8">
|
||||||
|
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
||||||
|
<meta name="viewport" content="width=device-width,initial-scale=1.0">
|
||||||
|
<link rel="icon" href="<%= BASE_URL %>favicon.ico">
|
||||||
|
<title>vue</title>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<noscript>
|
||||||
|
<strong>We're sorry but vue doesn't work properly without JavaScript enabled. Please enable it to continue.</strong>
|
||||||
|
</noscript>
|
||||||
|
<div id="app"></div>
|
||||||
|
<!-- built files will be auto injected -->
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
78
web/vue/src/App.vue
Normal file
78
web/vue/src/App.vue
Normal file
@@ -0,0 +1,78 @@
|
|||||||
|
<template>
|
||||||
|
<div id="app">
|
||||||
|
<img alt="Vue logo" src="./assets/logo.png">
|
||||||
|
<HelloWorld msg="Welcome to Your Vue.js App"/>
|
||||||
|
<p>{{ items }}</p>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
import HelloWorld from './components/HelloWorld.vue'
|
||||||
|
import RecipeDetails from './components/RecipeDetails.vue'
|
||||||
|
|
||||||
|
export default {
|
||||||
|
name: 'app',
|
||||||
|
components: {
|
||||||
|
HelloWorld,
|
||||||
|
RecipeDetails
|
||||||
|
},
|
||||||
|
data() {
|
||||||
|
return {
|
||||||
|
items: []
|
||||||
|
}
|
||||||
|
},
|
||||||
|
methods: {
|
||||||
|
setActiveCategory: function(id) {
|
||||||
|
this.active_category = id;
|
||||||
|
},
|
||||||
|
setActiveView: function(idx) {
|
||||||
|
this.active_view = idx;
|
||||||
|
},
|
||||||
|
closeActiveView: function() {
|
||||||
|
this.active_view = -1;
|
||||||
|
},
|
||||||
|
deleteRecipe: function(id) {
|
||||||
|
fetch("http://localhost:8000/api/delete/" + id)
|
||||||
|
.then((res) => res.json())
|
||||||
|
.then((data) => {
|
||||||
|
if (data === true) {
|
||||||
|
this.items.splice(this.active_view, 1);
|
||||||
|
this.closeActiveView();
|
||||||
|
console.log("Deleted :" + data);
|
||||||
|
} else {
|
||||||
|
console.log("Error deleting");
|
||||||
|
}})
|
||||||
|
.catch((err) => console.error(err));
|
||||||
|
},
|
||||||
|
fetchRecipesList: function() {
|
||||||
|
fetch("http://localhost:8000/api/list")
|
||||||
|
.then((res) => res.json())
|
||||||
|
.then((data) => this.items = data)
|
||||||
|
.catch(function(err) {
|
||||||
|
console.error(err);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
},
|
||||||
|
computed: {
|
||||||
|
displayed: function() {
|
||||||
|
return this.items.filter(
|
||||||
|
rec => rec.category == this.active_category
|
||||||
|
);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
mounted () {
|
||||||
|
this.fetchRecipesList();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<style>
|
||||||
|
#app {
|
||||||
|
font-family: 'Avenir', Helvetica, Arial, sans-serif;
|
||||||
|
-webkit-font-smoothing: antialiased;
|
||||||
|
-moz-osx-font-smoothing: grayscale;
|
||||||
|
text-align: center;
|
||||||
|
color: #2c3e50;
|
||||||
|
margin-top: 60px;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
BIN
web/vue/src/assets/logo.png
Normal file
BIN
web/vue/src/assets/logo.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 6.7 KiB |
37
web/vue/src/components/HelloWorld.vue
Normal file
37
web/vue/src/components/HelloWorld.vue
Normal file
@@ -0,0 +1,37 @@
|
|||||||
|
<template>
|
||||||
|
<div class="hello">
|
||||||
|
<h1>{{ msg }}</h1>
|
||||||
|
<p>
|
||||||
|
For a guide and recipes on how to configure / customize this project,<br>
|
||||||
|
check out the
|
||||||
|
<a href="https://cli.vuejs.org" target="_blank" rel="noopener">vue-cli documentation</a>.
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
export default {
|
||||||
|
name: 'HelloWorld',
|
||||||
|
props: {
|
||||||
|
msg: String
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<!-- Add "scoped" attribute to limit CSS to this component only -->
|
||||||
|
<style scoped>
|
||||||
|
h3 {
|
||||||
|
margin: 40px 0 0;
|
||||||
|
}
|
||||||
|
ul {
|
||||||
|
list-style-type: none;
|
||||||
|
padding: 0;
|
||||||
|
}
|
||||||
|
li {
|
||||||
|
display: inline-block;
|
||||||
|
margin: 0 10px;
|
||||||
|
}
|
||||||
|
a {
|
||||||
|
color: #42b983;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
22
web/vue/src/components/RecipeDetails.vue
Normal file
22
web/vue/src/components/RecipeDetails.vue
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
<template>
|
||||||
|
<div class="box">
|
||||||
|
<button @click="$emit('close')" class="button is-pulled-right">X close</button>
|
||||||
|
<h4 class="title">{{ item.title }}</h4>
|
||||||
|
<h6 class="subtitle">{{ categories[item.category].name }}</h6>
|
||||||
|
<p><strong>Ingredients : </strong></p>
|
||||||
|
<ul>
|
||||||
|
<li v-for="ing in item.ingredients.split('\n')">{{ ing }}</li>
|
||||||
|
</ul>
|
||||||
|
<button @click="$emit('delete', item.id)"
|
||||||
|
class="button is-danger is-pulled-right">
|
||||||
|
DELETE !
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
|
||||||
|
export default {
|
||||||
|
name: 'RecipeDetails',
|
||||||
|
props: ['item'],
|
||||||
|
}
|
||||||
0
web/vue/src/components/RecipeList.vue
Normal file
0
web/vue/src/components/RecipeList.vue
Normal file
8
web/vue/src/main.js
Normal file
8
web/vue/src/main.js
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
import Vue from 'vue'
|
||||||
|
import App from './App.vue'
|
||||||
|
|
||||||
|
Vue.config.productionTip = false
|
||||||
|
|
||||||
|
new Vue({
|
||||||
|
render: h => h(App),
|
||||||
|
}).$mount('#app')
|
||||||
Reference in New Issue
Block a user