Skip to content

Commit

Permalink
feat: show creation timestamps on pastes
Browse files Browse the repository at this point in the history
  • Loading branch information
Kyle Clemens committed Jul 1, 2018
1 parent 93fa437 commit 425a1c3
Show file tree
Hide file tree
Showing 21 changed files with 14,537 additions and 68 deletions.
6 changes: 3 additions & 3 deletions webserver/src/database/models/pastes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use super::files::{File as DbFile, NewFile};
use super::super::schema::{pastes, files};
use super::users::User;

use chrono::{NaiveDateTime, Utc};
use chrono::{NaiveDateTime, DateTime, Utc};

use diesel;
use diesel::prelude::*;
Expand Down Expand Up @@ -69,8 +69,8 @@ impl Paste {
self.description = description.map(|x| x.as_ref().to_string());
}

pub fn created_at(&self) -> &NaiveDateTime {
&self.created_at
pub fn created_at(&self) -> DateTime<Utc> {
DateTime::from_utc(self.created_at, Utc)
}

pub fn update(&mut self, conn: &DbConn, update: &MetadataUpdate) -> Result<()> {
Expand Down
3 changes: 3 additions & 0 deletions webserver/src/models/paste/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use chrono::{DateTime, Utc};

use diesel::backend::Backend;
use diesel::deserialize::{self, FromSql};
use diesel::Queryable;
Expand Down Expand Up @@ -33,6 +35,7 @@ pub struct Metadata {
pub description: Option<CountedText>,
#[serde(default)]
pub visibility: Visibility,
pub created_at: DateTime<Utc>,
}

#[derive(Debug, Clone, Serialize)]
Expand Down
5 changes: 4 additions & 1 deletion webserver/src/models/paste/output.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
use models::id::{DeletionKeyId, PasteId, FileId, UserId};
use super::{Paste, Metadata, Visibility, Content};

use chrono::{DateTime, Utc};

#[derive(Debug, Serialize)]
pub struct Output {
pub id: PasteId,
Expand All @@ -14,7 +16,7 @@ pub struct Output {
}

impl Output {
pub fn new<N, D, F>(paste_id: PasteId, author: Option<OutputAuthor>, name: Option<N>, desc: Option<D>, vis: Visibility, deletion_key: Option<DeletionKeyId>, files: F) -> Self
pub fn new<N, D, F>(paste_id: PasteId, author: Option<OutputAuthor>, name: Option<N>, desc: Option<D>, vis: Visibility, created_at: DateTime<Utc>, deletion_key: Option<DeletionKeyId>, files: F) -> Self
where N: AsRef<str>,
D: AsRef<str>,
F: IntoIterator<Item = OutputFile>,
Expand All @@ -27,6 +29,7 @@ impl Output {
name: name.map(|x| x.as_ref().to_string().into()),
description: desc.map(|x| x.as_ref().to_string().into()),
visibility: vis,
created_at,
},
files: Vec::new(),
},
Expand Down
2 changes: 2 additions & 0 deletions webserver/src/routes/api/pastes/get.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ fn _get_all(query: Option<AllQuery>, conn: DbConn) -> RouteResult<Vec<AllPaste>>
name: x.name().map(Into::into),
description: x.description().map(Into::into),
visibility: x.visibility(),
created_at: x.created_at(),
},
})
.collect();
Expand Down Expand Up @@ -108,6 +109,7 @@ fn _get(id: PasteId, query: Option<Query>, user: OptionalUser, conn: DbConn) ->
paste.name(),
paste.description(),
paste.visibility(),
paste.created_at(),
None,
files,
);
Expand Down
1 change: 1 addition & 0 deletions webserver/src/routes/api/pastes/post.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ fn post(info: InfoResult, user: OptionalUser, conn: DbConn) -> RouteResult<Outpu
paste.name(),
paste.description(),
paste.visibility(),
paste.created_at(),
deletion_key.map(|x| x.key()),
files,
);
Expand Down
1 change: 1 addition & 0 deletions webserver/src/routes/api/users/get.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ fn _get(page: u32, username: String, user: OptionalUser, conn: DbConn) -> RouteR
paste.name(),
paste.description(),
paste.visibility(),
paste.created_at(),
None,
output_files,
));
Expand Down
2 changes: 2 additions & 0 deletions webserver/src/routes/web/pastes/get.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ fn users_username_id(username: String, id: PasteId, config: State<Config>, user:
paste.name(),
paste.description(),
paste.visibility(),
paste.created_at(),
None,
files,
);
Expand Down Expand Up @@ -209,6 +210,7 @@ fn edit(username: String, id: PasteId, config: State<Config>, user: OptionalWebU
paste.name(),
paste.description(),
paste.visibility(),
paste.created_at(),
None,
files,
);
Expand Down
12 changes: 10 additions & 2 deletions webserver/src/routes/web/pastes/revisions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use database::models::users::User;
use database::schema::users;
use errors::*;
use models::id::PasteId;
use models::paste::output::{Output, OutputAuthor};
use models::paste::output::{Output, OutputAuthor, OutputFile};
use routes::web::{context, Rst, OptionalWebUser, Session};

use diesel::prelude::*;
Expand All @@ -17,6 +17,8 @@ use rocket::State;

use rocket_contrib::Template;

use std::result;

#[get("/pastes/<username>/<id>/revisions")]
fn get(username: String, id: PasteId, config: State<Config>, user: OptionalWebUser, mut sess: Session, conn: DbConn) -> Result<Rst> {
let paste: DbPaste = match id.get(&conn)? {
Expand Down Expand Up @@ -80,14 +82,20 @@ fn get(username: String, id: PasteId, config: State<Config>, user: OptionalWebUs
}
}

let files: Vec<OutputFile> = id.files(&conn)?
.iter()
.map(|x| x.as_output_file(false, &paste))
.collect::<result::Result<_, _>>()?;

let output = Output::new(
id,
author,
paste.name(),
paste.description(),
paste.visibility(),
paste.created_at(),
None,
None,
files,
);

let author_name = output.author.as_ref().map(|x| x.username.to_string()).unwrap_or_else(|| "anonymous".into());
Expand Down
1 change: 1 addition & 0 deletions webserver/src/routes/web/users/get.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ fn _get(page: u32, username: String, config: State<Config>, user: OptionalWebUse
paste.name(),
paste.description(),
paste.visibility(),
paste.created_at(),
None,
output_files,
));
Expand Down
14 changes: 14 additions & 0 deletions webserver/web/src/css/custom.scss
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,10 @@ table.is-middle td, table.is-middle th {
}

.box-title {
display: flex;
justify-content: space-between;
align-items: center;

padding: 1.25rem;
margin-left: -1.25rem;
margin-top: -1.25rem;
Expand Down Expand Up @@ -256,3 +260,13 @@ th, td {
content: attr(data-line-number);
}
}

.paste.info {
color: $grey;
font-style: italic;

:not(:first-child):not(:empty)::before {
content: ' / ';
color: $grey-light;
}
}
2 changes: 1 addition & 1 deletion webserver/web/static/css/dark-style.css

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion webserver/web/static/css/dark-style.css.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion webserver/web/static/css/style.css

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion webserver/web/static/css/style.css.map

Large diffs are not rendered by default.

0 comments on commit 425a1c3

Please sign in to comment.