Browse Source

GetUsers, GetUser, NewPost, GetPosts, GetPost

master
arnaucode 6 years ago
parent
commit
592bf9e8e8
22 changed files with 385 additions and 117 deletions
  1. +1
    -0
      .gitignore
  2. +110
    -6
      RESTfunctions.go
  3. +9
    -1
      main.go
  4. +30
    -0
      restRoutes.go
  5. +12
    -2
      webapp/app.js
  6. +7
    -1
      webapp/css/own.css
  7. +32
    -8
      webapp/fake_data.js
  8. +1
    -0
      webapp/index.html
  9. +1
    -1
      webapp/views/login/login.html
  10. +9
    -3
      webapp/views/main/main.js
  11. +2
    -2
      webapp/views/navbar.html
  12. +4
    -20
      webapp/views/post/post.html
  13. +8
    -9
      webapp/views/post/post.js
  14. +27
    -8
      webapp/views/signup/signup.html
  15. +9
    -6
      webapp/views/templates/post-thumb-template.html
  16. +22
    -0
      webapp/views/templates/user-thumb-template.html
  17. +7
    -20
      webapp/views/user/user.html
  18. +5
    -7
      webapp/views/user/user.js
  19. +28
    -0
      webapp/views/users/users.html
  20. +23
    -0
      webapp/views/users/users.js
  21. +10
    -20
      webapp/views/write/write.html
  22. +28
    -3
      webapp/views/write/write.js

+ 1
- 0
.gitignore

@ -1 +1,2 @@
keys keys
ownposts

+ 110
- 6
RESTfunctions.go

@ -4,16 +4,32 @@ import (
"encoding/json" "encoding/json"
"fmt" "fmt"
"net/http" "net/http"
"time"
"github.com/gorilla/mux"
"gopkg.in/mgo.v2/bson" "gopkg.in/mgo.v2/bson"
) )
type Post struct {
ID bson.ObjectId `json:"id" bson:"_id,omitempty"`
Title string `json:"title"`
Summary string `json:"summary"`
Date time.Time `json:"date"`
ThumbImg string `json:"thumbimg"`
Content string `json:"content"`
User User `json:"user"`
}
type User struct { type User struct {
Id bson.ObjectId `json:"id" bson:"_id,omitempty"`
Username string `json:"username"`
Email string `json:"email"`
Password string `json:"password"`
Token string `json:"token"`
ID bson.ObjectId `json:"id" bson:"_id,omitempty"`
Username string `json:"username"`
Name string `json:"name"`
LastName string `json:"lastname"`
Twitter string `json:"twitter" bson:",omitempty"`
Description string `json:"description" bson:",omitempty"`
Email string `json:"email" bson:",omitempty"`
Password string `json:"password" bson:",omitempty"`
Token string `json:"token" bson:",omitempty"`
Posts []Post `json:"posts" bson:",omitempty"`
} }
func Index(w http.ResponseWriter, r *http.Request) { func Index(w http.ResponseWriter, r *http.Request) {
@ -85,7 +101,7 @@ func Login(w http.ResponseWriter, r *http.Request) {
rUser.Token = token rUser.Token = token
//update with the token //update with the token
err = userCollection.Update(bson.M{"_id": rUser.Id}, rUser)
err = userCollection.Update(bson.M{"_id": rUser.ID}, rUser)
check(err) check(err)
jResp, err := json.Marshal(rUser) jResp, err := json.Marshal(rUser)
@ -94,3 +110,91 @@ func Login(w http.ResponseWriter, r *http.Request) {
} }
fmt.Fprintln(w, string(jResp)) fmt.Fprintln(w, string(jResp))
} }
func GetUsers(w http.ResponseWriter, r *http.Request) {
//get projects from mongodb
users := []User{}
err := userCollection.Find(bson.M{}).Limit(50).All(&users)
check(err)
jResp, err := json.Marshal(users)
check(err)
fmt.Fprintln(w, string(jResp))
}
func GetUser(w http.ResponseWriter, r *http.Request) {
vars := mux.Vars(r)
userid := vars["userid"]
//get projects from mongodb
user := User{}
err := userCollection.Find(bson.M{"_id": bson.ObjectIdHex(userid)}).One(&user)
check(err)
err = postCollection.Find(bson.M{"user._id": bson.ObjectIdHex(userid)}).Limit(50).All(&user.Posts)
check(err)
jResp, err := json.Marshal(user)
check(err)
fmt.Fprintln(w, string(jResp))
}
func NewPost(w http.ResponseWriter, r *http.Request) {
decoder := json.NewDecoder(r.Body)
var post Post
err := decoder.Decode(&post)
if err != nil {
panic(err)
}
defer r.Body.Close()
//get user by token
usertoken := r.Header.Get("Authorization")
user := User{}
err = userCollection.Find(bson.M{"token": usertoken}).One(&user)
check(err)
//add date to post
post.Date = time.Now()
//add user.id to post.user
post.User.ID = user.ID
err = postCollection.Insert(post)
check(err)
//get user
//user = User{}
err = userCollection.Find(bson.M{"token": usertoken}).One(&user)
check(err)
jResp, err := json.Marshal(user)
if err != nil {
panic(err)
}
fmt.Fprintln(w, string(jResp))
}
func GetPosts(w http.ResponseWriter, r *http.Request) {
//get projects from mongodb
posts := []Post{}
err := postCollection.Find(bson.M{}).Limit(50).All(&posts)
check(err)
jResp, err := json.Marshal(posts)
check(err)
fmt.Fprintln(w, string(jResp))
}
func GetPost(w http.ResponseWriter, r *http.Request) {
vars := mux.Vars(r)
postid := vars["postid"]
//get projects from mongodb
post := Post{}
err := postCollection.Find(bson.M{"_id": bson.ObjectIdHex(postid)}).One(&post)
check(err)
err = userCollection.Find(bson.M{"_id": post.User.ID}).One(&post.User)
check(err)
jResp, err := json.Marshal(post)
check(err)
fmt.Fprintln(w, string(jResp))
}

+ 9
- 1
main.go

@ -4,6 +4,7 @@ import (
"fmt" "fmt"
"log" "log"
"net/http" "net/http"
"os"
"github.com/fatih/color" "github.com/fatih/color"
"github.com/gorilla/handlers" "github.com/gorilla/handlers"
@ -15,6 +16,7 @@ const keysize = 2048
const hashize = 1536 const hashize = 1536
var userCollection *mgo.Collection var userCollection *mgo.Collection
var postCollection *mgo.Collection
func main() { func main() {
color.Blue("Starting ipfs-ai-models-market") color.Blue("Starting ipfs-ai-models-market")
@ -22,12 +24,18 @@ func main() {
readConfig("config.json") readConfig("config.json")
fmt.Println(config) fmt.Println(config)
//create models directory
_ = os.Mkdir(keysDir, os.ModePerm)
//create models directory
_ = os.Mkdir("ownposts", os.ModePerm)
initializeToken() initializeToken()
//mongodb //mongodb
session, err := getSession() session, err := getSession()
check(err) check(err)
userCollection = getCollection(session, "users") userCollection = getCollection(session, "users")
postCollection = getCollection(session, "posts")
//run thw webserver //run thw webserver
go GUI() go GUI()
@ -37,7 +45,7 @@ func main() {
log.Print("port: ") log.Print("port: ")
log.Println(config.APIPort) log.Println(config.APIPort)
router := NewRouter() router := NewRouter()
headersOk := handlers.AllowedHeaders([]string{"X-Requested-With", "Access-Control-Allow-Origin"})
headersOk := handlers.AllowedHeaders([]string{"X-Requested-With", "Access-Control-Allow-Origin", "Authorization"})
originsOk := handlers.AllowedOrigins([]string{"*"}) originsOk := handlers.AllowedOrigins([]string{"*"})
methodsOk := handlers.AllowedMethods([]string{"GET", "HEAD", "POST", "PUT", "OPTIONS"}) methodsOk := handlers.AllowedMethods([]string{"GET", "HEAD", "POST", "PUT", "OPTIONS"})
log.Fatal(http.ListenAndServe(":"+config.APIPort, handlers.CORS(originsOk, headersOk, methodsOk)(router))) log.Fatal(http.ListenAndServe(":"+config.APIPort, handlers.CORS(originsOk, headersOk, methodsOk)(router)))

+ 30
- 0
restRoutes.go

@ -21,4 +21,34 @@ var routes = Routes{
"/login", "/login",
Login, Login,
}, },
Route{
"GetUsers",
"GET",
"/users",
GetUsers,
},
Route{
"GetUser",
"GET",
"/user/{userid}",
GetUser,
},
Route{
"NewPost",
"POST",
"/post",
NewPost,
},
Route{
"GetPosts",
"GET",
"/posts",
GetPosts,
},
Route{
"GetPost",
"GET",
"/post/{postid}",
GetPost,
},
} }

+ 12
- 2
webapp/app.js

@ -12,6 +12,7 @@ angular.module('app', [
'app.login', 'app.login',
'app.main', 'app.main',
'app.newmodel', 'app.newmodel',
'app.users',
'app.user', 'app.user',
'app.post', 'app.post',
'app.write' 'app.write'
@ -37,7 +38,7 @@ console.log("window", window.location.hash);
localStorage.removeItem('dblog_user'); localStorage.removeItem('dblog_user');
localStorage.removeItem('dblog_user'); localStorage.removeItem('dblog_user');
window.location='#!/main';
//window.location='#!/main';
$routeProvider.otherwise({redirectTo: '/main'}); $routeProvider.otherwise({redirectTo: '/main'});
} }
} }
@ -76,6 +77,7 @@ console.log("window", window.location.hash);
.factory('api', function($http) { .factory('api', function($http) {
return { return {
init: function() { init: function() {
console.log("http", $http.options);
var dblog_user = JSON.parse(localStorage.getItem('dblog_user')); var dblog_user = JSON.parse(localStorage.getItem('dblog_user'));
if (dblog_user) { if (dblog_user) {
$http.defaults.headers.common['Authorization'] = dblog_user.token; $http.defaults.headers.common['Authorization'] = dblog_user.token;
@ -86,4 +88,12 @@ console.log("window", window.location.hash);
}) })
.run(function(api) { .run(function(api) {
api.init(); api.init();
});
})
.config(function($sceDelegateProvider) {
$sceDelegateProvider.resourceUrlWhitelist([
// Allow same origin resource loads.
'self',
// Allow loading from outer templates domain.
'http://localhost:8080/**'
]);
});

+ 7
- 1
webapp/css/own.css

@ -32,7 +32,7 @@ a, a:hover {
} }
.o_userImgCircular { .o_userImgCircular {
width: 60px;
width: 40px;
background: #ffffff; background: #ffffff;
border-radius: 150px; border-radius: 150px;
-webkit-border-radius: 150px; -webkit-border-radius: 150px;
@ -46,3 +46,9 @@ a, a:hover {
width: 50%; width: 50%;
width: 50%; width: 50%;
} }
.o_card-body {
padding-left:1.25rem;
padding-right:1.25rem;
padding-top:0.8rem;
}

+ 32
- 8
webapp/fake_data.js

@ -9,25 +9,37 @@ var user = {
title: "This is the second post", title: "This is the second post",
subtitle: "this is the subtitle of the second post", subtitle: "this is the subtitle of the second post",
img: "https://cdn-images-1.medium.com/fit/t/800/240/1*4_E6m7J0112DBi1Lmdniiw.png", img: "https://cdn-images-1.medium.com/fit/t/800/240/1*4_E6m7J0112DBi1Lmdniiw.png",
content: "Some quick example text to build on the card title and make up the bulk of the card's content."
content: "Some quick example text to build on the card title and make up the bulk of the card's content.",
user: {
id: "5a732c952f009b384d5effb7"
}
}, },
{ {
title: "This is the first post", title: "This is the first post",
subtitle: "this is the subtitle of the first post", subtitle: "this is the subtitle of the first post",
img: "https://bootstrap-themes.github.io/application/assets/img/unsplash_1.jpg", img: "https://bootstrap-themes.github.io/application/assets/img/unsplash_1.jpg",
content: "Some quick example text to build on the card title and make up the bulk of the card's content."
content: "Some quick example text to build on the card title and make up the bulk of the card's content.",
user: {
id: "5a732c952f009b384d5effb7"
}
}, },
{ {
title: "Thinking about python development", title: "Thinking about python development",
subtitle: "this is the subtitle of the second post", subtitle: "this is the subtitle of the second post",
img: "https://cdn.static-economist.com/sites/default/files/images/2015/09/blogs/economist-explains/code2.png", img: "https://cdn.static-economist.com/sites/default/files/images/2015/09/blogs/economist-explains/code2.png",
content: "Some quick example text to build on the card title and make up the bulk of the card's content."
content: "Some quick example text to build on the card title and make up the bulk of the card's content.",
user: {
id: "5a732c952f009b384d5effb7"
}
}, },
{ {
title: "Thinking about G", title: "Thinking about G",
subtitle: "this is the subtitle of the first post", subtitle: "this is the subtitle of the first post",
img: "https://cdn-images-1.medium.com/max/1600/1*RNkyx-Zq7w61eR74nMYgnA.jpeg", img: "https://cdn-images-1.medium.com/max/1600/1*RNkyx-Zq7w61eR74nMYgnA.jpeg",
content: "Some quick example text to build on the card title and make up the bulk of the card's content."
content: "Some quick example text to build on the card title and make up the bulk of the card's content.",
user: {
id: "5a732c952f009b384d5effb7"
}
} }
] ]
}; };
@ -35,13 +47,19 @@ var featured_posts = [{
title: "Thinking about python development", title: "Thinking about python development",
subtitle: "this is the subtitle of the second post", subtitle: "this is the subtitle of the second post",
img: "https://cdn.static-economist.com/sites/default/files/images/2015/09/blogs/economist-explains/code2.png", img: "https://cdn.static-economist.com/sites/default/files/images/2015/09/blogs/economist-explains/code2.png",
content: "Some quick example text to build on the card title and make up the bulk of the card's content."
content: "Some quick example text to build on the card title and make up the bulk of the card's content.",
user: {
id: "5a732c952f009b384d5effb7"
}
}, },
{ {
title: "Thinking about G", title: "Thinking about G",
subtitle: "this is the subtitle of the first post", subtitle: "this is the subtitle of the first post",
img: "https://cdn-images-1.medium.com/max/1600/1*RNkyx-Zq7w61eR74nMYgnA.jpeg", img: "https://cdn-images-1.medium.com/max/1600/1*RNkyx-Zq7w61eR74nMYgnA.jpeg",
content: "Some quick example text to build on the card title and make up the bulk of the card's content."
content: "Some quick example text to build on the card title and make up the bulk of the card's content.",
user: {
id: "5a732c952f009b384d5effb7"
}
} }
]; ];
@ -49,13 +67,19 @@ var posts = [{
title: "This is the second post", title: "This is the second post",
subtitle: "this is the subtitle of the second post", subtitle: "this is the subtitle of the second post",
img: "https://cdn-images-1.medium.com/fit/t/800/240/1*4_E6m7J0112DBi1Lmdniiw.png", img: "https://cdn-images-1.medium.com/fit/t/800/240/1*4_E6m7J0112DBi1Lmdniiw.png",
content: "Some quick example text to build on the card title and make up the bulk of the card's content."
content: "Some quick example text to build on the card title and make up the bulk of the card's content.",
user: {
id: "5a732c952f009b384d5effb7"
}
}, },
{ {
title: "This is the first post", title: "This is the first post",
subtitle: "this is the subtitle of the first post", subtitle: "this is the subtitle of the first post",
img: "https://bootstrap-themes.github.io/application/assets/img/unsplash_1.jpg", img: "https://bootstrap-themes.github.io/application/assets/img/unsplash_1.jpg",
content: "Some quick example text to build on the card title and make up the bulk of the card's content."
content: "Some quick example text to build on the card title and make up the bulk of the card's content.",
user: {
id: "5a732c952f009b384d5effb7"
}
}, },
{ {
title: "Thinking about python development", title: "Thinking about python development",

+ 1
- 0
webapp/index.html

@ -68,6 +68,7 @@ Works for both browser and electron with the same code -->
<script src="views/login/login.js"></script> <script src="views/login/login.js"></script>
<script src="views/main/main.js"></script> <script src="views/main/main.js"></script>
<script src="views/newmodel/newmodel.js"></script> <script src="views/newmodel/newmodel.js"></script>
<script src="views/users/users.js"></script>
<script src="views/user/user.js"></script> <script src="views/user/user.js"></script>
<script src="views/post/post.js"></script> <script src="views/post/post.js"></script>
<script src="views/write/write.js"></script> <script src="views/write/write.js"></script>

+ 1
- 1
webapp/views/login/login.html

@ -1,4 +1,4 @@
<div class="container" style="margin-top: -60px;">
<div class="container">
<div class="row"> <div class="row">
<div class="col-sm-3"> <div class="col-sm-3">

+ 9
- 3
webapp/views/main/main.js

@ -12,8 +12,14 @@ angular.module('app.main', ['ngRoute'])
.controller('MainCtrl', function($scope, $rootScope, $http) { .controller('MainCtrl', function($scope, $rootScope, $http) {
$scope.user = user;
$scope.featured_posts= featured_posts;
$scope.posts = posts;
$scope.posts = {};
$http.get(apiurl + 'posts')
.then(function(data) {
console.log('data success');
console.log(data);
$scope.posts = data.data;
}, function(data) {
console.log('no user');
});
}); });

+ 2
- 2
webapp/views/navbar.html

@ -1,5 +1,5 @@
<div ng-controller="NavbarCtrl"> <div ng-controller="NavbarCtrl">
<nav class="navbar navbar-expand-lg navbar-dark c_blue500">
<nav class="navbar navbar-expand-lg navbar-dark c_blueGrey700">
<a class="navbar-brand" href="#"> <a class="navbar-brand" href="#">
<i title="Server" class="fa fa-cube fa-1x"></i> decentralized-blogging-platform <i title="Server" class="fa fa-cube fa-1x"></i> decentralized-blogging-platform
</a> </a>
@ -13,7 +13,7 @@
<a class="nav-link" href="#">Top Posts <span class="sr-only">(current)</span></a> <a class="nav-link" href="#">Top Posts <span class="sr-only">(current)</span></a>
</li> </li>
<li class="nav-item"> <li class="nav-item">
<a class="nav-link" href="#">Top Writters</a>
<a class="nav-link" href="#!/users">Top Writters</a>
</li> </li>
<form class="form-inline my-2 my-lg-0"> <form class="form-inline my-2 my-lg-0">
<input class="form-control mr-sm-2" type="search" placeholder="Search" aria-label="Search"> <input class="form-control mr-sm-2" type="search" placeholder="Search" aria-label="Search">

+ 4
- 20
webapp/views/post/post.html

@ -1,26 +1,7 @@
<div class="container"> <div class="container">
<div class="row"> <div class="row">
<div class="col-sm-3"> <div class="col-sm-3">
<div class="card">
<div class="o_userProfileBackground">
</div>
<div class="card-body">
<img class="o_userImgCircular o_profilePageImage" ng-src="https://www.eyerys.com/sites/default/files/mark_zuckerberg.jpg" />
<h4>
{{user.name}} {{user.lastname}}
</h4>
<h6 class="card-subtitle mb-2 text-muted">@{{user.username}}</h6>
<p>{{user.description}}</p>
<p>
<a ng-href="#!/userLikes/{{user._id}}">
14 followers
</a> |
<a ng-href="#!/userLikes/{{user._id}}">
20 following
</a>
</p>
</div>
</div>
<div ng-include="'views/templates/user-thumb-template.html'"></div>
<br> <br>
<div class="card"> <div class="card">
<div class="card-body"> <div class="card-body">
@ -41,6 +22,9 @@
<h6 class="card-subtitle mb-2 text-muted">{{post.subtitle}}</h6> <h6 class="card-subtitle mb-2 text-muted">{{post.subtitle}}</h6>
<img ng-src="{{post.img}}" class="img-fluid" /> <img ng-src="{{post.img}}" class="img-fluid" />
<p class="card-text">{{post.content}}</p> <p class="card-text">{{post.content}}</p>
<div ng-include="'http://localhost:8080/ipfs/QmUv3dQuNREHnEFYs7JkqyxZjYfEXd4t9jej5jY2dPVaqU'"></div>
<div class="pull-right"> <div class="pull-right">
<i title="Server" class="fa fa-heart ct_red300 fa-1x"></i> 37 <i title="Server" class="fa fa-heart ct_red300 fa-1x"></i> 37
</div> </div>

+ 8
- 9
webapp/views/post/post.js

@ -3,23 +3,22 @@
angular.module('app.post', ['ngRoute']) angular.module('app.post', ['ngRoute'])
.config(['$routeProvider', function($routeProvider) { .config(['$routeProvider', function($routeProvider) {
$routeProvider.when('/post', {
$routeProvider.when('/post/:postid', {
templateUrl: 'views/post/post.html', templateUrl: 'views/post/post.html',
controller: 'PostCtrl' controller: 'PostCtrl'
}); });
}]) }])
.controller('PostCtrl', function($scope, $rootScope, $http) {
/*$http.get(apiurl + 'user/' + )
.controller('PostCtrl', function($scope, $rootScope, $http, $routeParams) {
$scope.post = {};
$scope.user = {};
$http.get(apiurl + 'post/' + $routeParams.postid)
.then(function(data) { .then(function(data) {
console.log('data success'); console.log('data success');
console.log(data); console.log(data);
$scope.user = data.data;
$scope.post = data.data;
$scope.user = $scope.post.user;
}, function(data) { }, function(data) {
console.log('no user'); console.log('no user');
});*/
//fake data
$scope.user = user;
$scope.post = user.posts[0];
});
}); });

+ 27
- 8
webapp/views/signup/signup.html

@ -1,4 +1,4 @@
<div class="container" style="margin-top: -80px;">
<div class="container">
<div class="row"> <div class="row">
<div class="col-sm-3"> <div class="col-sm-3">
@ -9,15 +9,34 @@
<h4 class="card-title"> <h4 class="card-title">
Signup Signup
</h4> </h4>
<div class="form-group">
<input ng-model="user.username" class="form-control" placeholder="Username">
</div>
<div class="form-group">
<input ng-model="user.email" type="email" class="form-control" placeholder="Email">
<input ng-model="user.email" type="email" class="form-control" placeholder="Email">
<br>
<input ng-model="user.password" type="password" class="form-control" placeholder="Password">
<br>
<div class="row">
<div class="col-sm-12">
<div style="display:inline-block;">
@
</div>
<div style="display:inline-block;">
<input ng-model="user.username" class="form-control" placeholder="Username">
</div>
</div>
</div> </div>
<div class="form-group">
<input ng-model="user.password" type="password" class="form-control" placeholder="Password">
<br>
<div class="row">
<div class="col-sm-6">
<input ng-model="user.name" class="form-control" placeholder="Name">
</div>
<div class="col-sm-6">
<input ng-model="user.lastname" class="form-control" placeholder="Last Name">
</div>
</div> </div>
<br>
<textarea ng-model="user.description" class="form-control" rows="3" placeholder="Description"></textarea>
<br>
<div class="row"> <div class="row">
<div class="col-sm-6"> <div class="col-sm-6">
<a href="#!/login" class="btn btn-raised btn-block c_o_blue300">Cancel</a> <a href="#!/login" class="btn btn-raised btn-block c_o_blue300">Cancel</a>

+ 9
- 6
webapp/views/templates/post-thumb-template.html

@ -1,19 +1,22 @@
<div class="card"> <div class="card">
<div class="card-body">
<a ng-href="#!/user/{{user.id}}" class="row">
<div class="col-sm-3">
<div class="o_card-body">
<a ng-href="#!/user/{{post.user.id}}">
<div class="row">
<div style="display:block;margin-left:10px;margin-right:10px;">
<img class="o_userImgCircular" ng-src="https://www.eyerys.com/sites/default/files/mark_zuckerberg.jpg" /> <img class="o_userImgCircular" ng-src="https://www.eyerys.com/sites/default/files/mark_zuckerberg.jpg" />
</div> </div>
<div class="col-sm-8">
<div style="display:block; font-size:90%;">
<b>{{user.name}} {{user.lastname}}</b> <b>{{user.name}} {{user.lastname}}</b>
<div class="mb-2 text-muted">@{{user.username}}</div> <div class="mb-2 text-muted">@{{user.username}}</div>
</div> </div>
</div>
</a> </a>
</div> </div>
<a ng-href="#!/post/{{post.id}}" class="card-body">
<a ng-href="#!/post/{{post.id}}" class="o_card-body">
<img ng-src="{{post.img}}" class="img-fluid" />
<br><br>
<h5 class="card-title">{{post.title}}</h5> <h5 class="card-title">{{post.title}}</h5>
<h6 class="card-subtitle mb-2 text-muted">{{post.subtitle}}</h6> <h6 class="card-subtitle mb-2 text-muted">{{post.subtitle}}</h6>
<img ng-src="{{post.img}}" class="img-fluid" />
<p class="card-text">{{post.content}}</p> <p class="card-text">{{post.content}}</p>
<div class="pull-right"> <div class="pull-right">
<i title="Server" class="fa fa-heart ct_red300 fa-1x"></i> 37 <i title="Server" class="fa fa-heart ct_red300 fa-1x"></i> 37

+ 22
- 0
webapp/views/templates/user-thumb-template.html

@ -0,0 +1,22 @@
<div class="card">
<a ng-href="#!/user/{{user.id}}">
<div class="o_userProfileBackground">
</div>
<div class="card-body">
<img class="o_userImgCircular o_profilePageImage" ng-src="https://www.eyerys.com/sites/default/files/mark_zuckerberg.jpg" />
<h4>
{{user.name}} {{user.lastname}}
</h4>
<h6 class="card-subtitle mb-2 text-muted">@{{user.username}}</h6>
<p>{{user.description}}</p>
<p>
<a ng-href="#!/userLikes/{{user._id}}">
14 followers
</a> |
<a ng-href="#!/userLikes/{{user._id}}">
20 following
</a>
</p>
</div>
</a>
</div>

+ 7
- 20
webapp/views/user/user.html

@ -1,26 +1,7 @@
<div class="container"> <div class="container">
<div class="row"> <div class="row">
<div class="col-sm-3"> <div class="col-sm-3">
<div class="card">
<div class="o_userProfileBackground">
</div>
<div class="card-body">
<img class="o_userImgCircular o_profilePageImage" ng-src="https://www.eyerys.com/sites/default/files/mark_zuckerberg.jpg" />
<h4>
{{user.name}} {{user.lastname}}
</h4>
<h6 class="card-subtitle mb-2 text-muted">@{{user.username}}</h6>
<p>{{user.description}}</p>
<p>
<a ng-href="#!/userLikes/{{user._id}}">
14 followers
</a> |
<a ng-href="#!/userLikes/{{user._id}}">
20 following
</a>
</p>
</div>
</div>
<div ng-include="'views/templates/user-thumb-template.html'"></div>
<br> <br>
<div class="card"> <div class="card">
<div class="card-body"> <div class="card-body">
@ -35,10 +16,16 @@
</div> </div>
</div> </div>
<div class="col-sm-6"> <div class="col-sm-6">
<div ng-repeat="post in user.posts"> <div ng-repeat="post in user.posts">
<div ng-include="'views/templates/post-thumb-template.html'"></div> <div ng-include="'views/templates/post-thumb-template.html'"></div>
<br> <br>
</div> </div>
<div ng-show="!user.posts" class="card">
<div class="card-body">
<h5>No articles yet</h5>
</div>
</div>
</div> </div>
<div class="col-sm-3"> <div class="col-sm-3">
<div class="card"> <div class="card">

+ 5
- 7
webapp/views/user/user.js

@ -3,23 +3,21 @@
angular.module('app.user', ['ngRoute']) angular.module('app.user', ['ngRoute'])
.config(['$routeProvider', function($routeProvider) { .config(['$routeProvider', function($routeProvider) {
$routeProvider.when('/user', {
$routeProvider.when('/user/:userid', {
templateUrl: 'views/user/user.html', templateUrl: 'views/user/user.html',
controller: 'UserCtrl' controller: 'UserCtrl'
}); });
}]) }])
.controller('UserCtrl', function($scope, $rootScope, $http) {
/*$http.get(apiurl + 'user/' + )
.controller('UserCtrl', function($scope, $rootScope, $http, $routeParams) {
$scope.user = {};
$http.get(apiurl + 'user/' + $routeParams.userid)
.then(function(data) { .then(function(data) {
console.log('data success'); console.log('data success');
console.log(data); console.log(data);
$scope.user = data.data; $scope.user = data.data;
}, function(data) { }, function(data) {
console.log('no user'); console.log('no user');
});*/
//fake data
$scope.user = user;
});
$scope.featured_posts= featured_posts; $scope.featured_posts= featured_posts;
}); });

+ 28
- 0
webapp/views/users/users.html

@ -0,0 +1,28 @@
<div class="container">
<div class="row">
<div class="col-sm-4">
<div ng-repeat="user in users" ng-if="$index % 3 == 0">
<a ng-href="#!/user/{{user.id}}">
<div ng-include="'views/templates/user-thumb-template.html'"></div>
</a>
<br>
</div>
</div>
<div class="col-sm-4">
<div ng-repeat="user in users" ng-if="$index % 3 == 1">
<a ng-href="#!/user/{{user.id}}">
<div ng-include="'views/templates/user-thumb-template.html'"></div>
</a>
<br>
</div>
</div>
<div class="col-sm-4">
<div ng-repeat="user in users" ng-if="$index % 3 == 2">
<a ng-href="#!/user/{{user.id}}">
<div ng-include="'views/templates/user-thumb-template.html'"></div>
</a>
<br>
</div>
</div>
</div>
</div>

+ 23
- 0
webapp/views/users/users.js

@ -0,0 +1,23 @@
'use strict';
angular.module('app.users', ['ngRoute'])
.config(['$routeProvider', function($routeProvider) {
$routeProvider.when('/users', {
templateUrl: 'views/users/users.html',
controller: 'UsersCtrl'
});
}])
.controller('UsersCtrl', function($scope, $rootScope, $http) {
$scope.users = {};
$http.get(apiurl + 'users')
.then(function(data) {
console.log('data success');
console.log(data);
$scope.users = data.data;
}, function(data) {
console.log('no user');
});
});

+ 10
- 20
webapp/views/write/write.html

@ -2,24 +2,7 @@
<div class="row"> <div class="row">
<div class="col-sm-3"> <div class="col-sm-3">
<div class="card"> <div class="card">
<div class="o_userProfileBackground">
</div>
<div class="card-body">
<img class="o_userImgCircular o_profilePageImage" ng-src="https://www.eyerys.com/sites/default/files/mark_zuckerberg.jpg" />
<h4>
{{user.name}} {{user.lastname}}
</h4>
<h6 class="card-subtitle mb-2 text-muted">@{{user.username}}</h6>
<p>{{user.description}}</p>
<p>
<a ng-href="#!/userLikes/{{user._id}}">
14 followers
</a> |
<a ng-href="#!/userLikes/{{user._id}}">
20 following
</a>
</p>
</div>
<div ng-include="'views/templates/user-thumb-template.html'"></div>
</div> </div>
<br> <br>
<div class="card"> <div class="card">
@ -38,11 +21,18 @@
<div class="row"> <div class="row">
<div class="col-sm-10"> <div class="col-sm-10">
<div class="form-group"> <div class="form-group">
<input type="text" class="form-control" placeholder="Title of the article..." style="font-weight:bold;">
<input ng-model="post.title" type="text" class="form-control" placeholder="Title of the article..." style="font-weight:bold;">
</div> </div>
</div> </div>
<div class="col-sm-2"> <div class="col-sm-2">
<div ng-click="save()" class="btn btn-raised btn-block c_o_blue300 pull-right">Publicate</div>
<div ng-click="publicate()" class="btn btn-raised btn-block c_o_blue300 pull-right">Publicate</div>
</div>
</div>
<div class="row">
<div class="col-sm-12">
<div class="form-group">
<input ng-model="post.summary" type="text" class="form-control" placeholder="Summary of the article...">
</div>
</div> </div>
</div> </div>
<div class="card"> <div class="card">

+ 28
- 3
webapp/views/write/write.js

@ -10,7 +10,11 @@ angular.module('app.write', ['ngRoute'])
}]) }])
.controller('WriteCtrl', function($scope, $rootScope, $http) { .controller('WriteCtrl', function($scope, $rootScope, $http) {
$scope.content = "";
$scope.post = {
title: "",
content: "",
summary: ""
};
var editor = new MediumEditor('.editable', { var editor = new MediumEditor('.editable', {
toolbar: { toolbar: {
/* These are the default options for the toolbar, /* These are the default options for the toolbar,
@ -35,8 +39,29 @@ angular.module('app.write', ['ngRoute'])
} }
}).subscribe('editableInput', function (event, editable) { }).subscribe('editableInput', function (event, editable) {
// Do some work // Do some work
$scope.content = editable.innerHTML;
console.log($scope.content);
$scope.post.content = editable.innerHTML;
console.log($scope.post.content);
}); });
$scope.publicate = function() {
console.log("post", $scope.post);
$http({
url: apiurl + 'post',
method: "POST",
headers: {
"Content-Type": undefined
},
data: $scope.post
})
.then(function(data) {
console.log("data: ");
console.log(data.data);
window.location = "#!/user/" + $scope.user.id;
},
function(data) {
console.log(data);
});
};
}); });

Loading…
Cancel
Save