Kaynağa Gözat

Implement Categories and Comments features (via Codex)

pull/5/head
Nano 6 gün önce
ebeveyn
işleme
5fc5662cc8
7 değiştirilmiş dosya ile 328 ekleme ve 89 silme
  1. +131
    -65
      app/controllers/CategoriesController.asp
  2. +62
    -19
      app/controllers/CommentsController.asp
  3. +9
    -5
      app/repositories/CategoriesRepository.asp
  4. +35
    -0
      app/views/Categories/edit.asp
  5. +43
    -0
      app/views/Categories/index.asp
  6. +31
    -0
      app/views/Categories/new.asp
  7. +17
    -0
      app/views/Categories/show.asp

+ 131
- 65
app/controllers/CategoriesController.asp Dosyayı Görüntüle

@@ -34,71 +34,137 @@ Class CategoriesController_Class
m_title = v
End Property
'---------------------------------------------------------------
' Action: Index
'---------------------------------------------------------------
Public Sub Index()
' TODO: Implement Index action
Response.Write "Index action called"
End Sub
'---------------------------------------------------------------
' Action: Show
'---------------------------------------------------------------
Public Sub Show(id)
' TODO: Implement Show action
Response.Write "<strong>Show called</strong><br>"
Response.Write "Parameters:<br>"
Response.Write "id = " & Server.HTMLEncode(CStr(id)) & "<br>"
End Sub
'---------------------------------------------------------------
' Action: New
'---------------------------------------------------------------
Public Sub NewForm()
' TODO: Implement NewForm action
Response.Write "NewForm action called"
End Sub
'---------------------------------------------------------------
' Action: Create
'---------------------------------------------------------------
Public Sub Create()
' TODO: Implement Create action
Response.Write "Create action called"
End Sub
'---------------------------------------------------------------
' Action: Edit
'---------------------------------------------------------------
Public Sub Edit(id)
' TODO: Implement Edit action
Response.Write "<strong>Edit called</strong><br>"
Response.Write "Parameters:<br>"
Response.Write "id = " & Server.HTMLEncode(CStr(id)) & "<br>"
End Sub
'---------------------------------------------------------------
' Action: Update
'---------------------------------------------------------------
Public Sub Update(id)
' TODO: Implement Update action
Response.Write "<strong>Update called</strong><br>"
Response.Write "Parameters:<br>"
Response.Write "id = " & Server.HTMLEncode(CStr(id)) & "<br>"
End Sub
'---------------------------------------------------------------
' Action: Delete
'---------------------------------------------------------------
Public Sub Delete(id)
' TODO: Implement Delete action
Response.Write "<strong>Delete called</strong><br>"
Response.Write "Parameters:<br>"
Response.Write "id = " & Server.HTMLEncode(CStr(id)) & "<br>"
End Sub
End Class
'---------------------------------------------------------------
' Action: Index
'---------------------------------------------------------------
Public Sub Index()
Dim categories
Set categories = CategoriesRepository().FindAll
%>
<!--#include file="../views/Categories/index.asp" -->
<%
End Sub

'---------------------------------------------------------------
' Action: Show
'---------------------------------------------------------------
Public Sub Show(ByVal id)
Dim category
On Error Resume Next
Set category = CategoriesRepository().FindByID(id)
If Err.Number <> 0 Then
Err.Clear
On Error GoTo 0
Response.Status = "404 Not Found"
%>
<!--#include file="../views/Error/NotFound.asp" -->
<%
Exit Sub
End If
On Error GoTo 0
%>
<!--#include file="../views/Categories/show.asp" -->
<%
End Sub

'---------------------------------------------------------------
' Action: New
'---------------------------------------------------------------
Public Sub NewForm()
%>
<!--#include file="../views/Categories/new.asp" -->
<%
End Sub

'---------------------------------------------------------------
' Action: Create
'---------------------------------------------------------------
Public Sub Create()
Dim name : name = Trim(Request.Form("Name"))
If Len(name) = 0 Then
Flash().AddError "Name is required."
Response.Redirect "/categories/new"
Exit Sub
End If

Dim category
Set category = New POBO_Categories

category.Name = name
category.Slug = Request.Form("Slug")
category.Description = Request.Form("Description")

CategoriesRepository().AddNew category
Flash().Success = "Category created."
Response.Redirect "/categories"
End Sub

'---------------------------------------------------------------
' Action: Edit
'---------------------------------------------------------------
Public Sub Edit(ByVal id)
Dim category
On Error Resume Next
Set category = CategoriesRepository().FindByID(id)
If Err.Number <> 0 Then
Err.Clear
On Error GoTo 0
Response.Status = "404 Not Found"
%>
<!--#include file="../views/Error/NotFound.asp" -->
<%
Exit Sub
End If
On Error GoTo 0
%>
<!--#include file="../views/Categories/edit.asp" -->
<%
End Sub

'---------------------------------------------------------------
' Action: Update
'---------------------------------------------------------------
Public Sub Update(ByVal id)
Dim category
On Error Resume Next
Set category = CategoriesRepository().FindByID(id)
If Err.Number <> 0 Then
Err.Clear
On Error GoTo 0
Response.Status = "404 Not Found"
%>
<!--#include file="../views/Error/NotFound.asp" -->
<%
Exit Sub
End If
On Error GoTo 0

Dim name : name = Trim(Request.Form("Name"))
If Len(name) = 0 Then
Flash().AddError "Name is required."
Response.Redirect "/categories/" & Server.URLEncode(CStr(id)) & "/edit"
Exit Sub
End If

category.Name = name
category.Slug = Request.Form("Slug")
category.Description = Request.Form("Description")

CategoriesRepository().Update category
Flash().Success = "Category updated."
Response.Redirect "/categories"
End Sub

'---------------------------------------------------------------
' Action: Delete
'---------------------------------------------------------------
Public Sub Delete(ByVal id)
CategoriesRepository().Delete id
Flash().Success = "Category deleted."
Response.Redirect "/categories"
End Sub

End Class
' Singleton instance
Dim CategoriesController_Class__Singleton


+ 62
- 19
app/controllers/CommentsController.asp Dosyayı Görüntüle

@@ -34,25 +34,68 @@ Class CommentsController_Class
m_title = v
End Property
'---------------------------------------------------------------
' Action: Create
'---------------------------------------------------------------
Public Sub Create()
' TODO: Implement Create action
Response.Write "Create action called"
End Sub
'---------------------------------------------------------------
' Action: Delete
'---------------------------------------------------------------
Public Sub Delete(id)
' TODO: Implement Delete action
Response.Write "<strong>Delete called</strong><br>"
Response.Write "Parameters:<br>"
Response.Write "id = " & Server.HTMLEncode(CStr(id)) & "<br>"
End Sub
End Class
'---------------------------------------------------------------
' Action: Create
'---------------------------------------------------------------
Public Sub Create()
Dim comment
Set comment = New POBO_Comments

comment.PostID = FormNumberOrZero(Request.Form("PostID"))
comment.AuthorName = Request.Form("AuthorName")
comment.AuthorEmail = Request.Form("AuthorEmail")
comment.Body = Request.Form("Body")
comment.CreatedDate = Now()
comment.IsApproved = 0

CommentsRepository().AddNew comment
Flash().Success = "Comment submitted for approval."

Dim slug : slug = ResolvePostSlug(comment.PostID)
If Len(slug) > 0 Then
Response.Redirect "/posts/" & Server.URLEncode(slug)
Else
Response.Redirect "/posts"
End If
End Sub

'---------------------------------------------------------------
' Action: Delete
'---------------------------------------------------------------
Public Sub Delete(ByVal id)
CommentsRepository().Delete id
Flash().Success = "Comment deleted."

Dim returnUrl : returnUrl = Request.ServerVariables("HTTP_REFERER")
If Len(returnUrl) = 0 Then returnUrl = "/posts"
Response.Redirect returnUrl
End Sub

Private Function FormNumberOrZero(ByVal value)
If IsNumeric(value) Then
FormNumberOrZero = CLng(value)
Else
FormNumberOrZero = 0
End If
End Function

Private Function ResolvePostSlug(ByVal postID)
Dim slug : slug = Trim(Request.Form("Slug"))
If Len(slug) = 0 Then slug = Trim(Request.Form("PostSlug"))

If Len(slug) = 0 And CLng(postID) > 0 Then
Dim post
On Error Resume Next
Set post = PostsRepository().FindByID(postID)
If Err.Number = 0 Then slug = CStr(post.Slug)
Err.Clear
On Error GoTo 0
End If

ResolvePostSlug = slug
End Function

End Class
' Singleton instance
Dim CommentsController_Class__Singleton


+ 9
- 5
app/repositories/CategoriesRepository.asp Dosyayı Görüntüle

@@ -23,11 +23,15 @@ Class CategoriesRepository_Class
Destroy rs
End Function
Public Function GetAll(orderBy)
Set GetAll = Find(Empty, orderBy)
End Function
Public Function Find(where_kvarray, order_string_or_array)
Public Function GetAll(orderBy)
Set GetAll = Find(Empty, orderBy)
End Function

Public Function FindAll()
Set FindAll = Find(Empty, "Name")
End Function

Public Function Find(where_kvarray, order_string_or_array)
Dim sql : sql = "Select [CategoryID], [Description], [Name], [Slug] FROM [Categories]"
Dim where_keys, where_values, i
If Not IsEmpty(where_kvarray) Then


+ 35
- 0
app/views/Categories/edit.asp Dosyayı Görüntüle

@@ -0,0 +1,35 @@
<div class="row">
<div class="col-lg-8">
<div class="card shadow-sm">
<div class="card-body">
<h1 class="h3 mb-4">Edit Category</h1>

<form method="post" action="/categories/<%= H(category.CategoryID) %>">
<div class="mb-3">
<label class="form-label" for="Name">Name</label>
<input class="form-control" type="text" id="Name" name="Name" value="<%= H(category.Name) %>" required>
</div>

<div class="mb-3">
<label class="form-label" for="Slug">Slug</label>
<input class="form-control" type="text" id="Slug" name="Slug" value="<%= H(category.Slug) %>">
</div>

<div class="mb-4">
<label class="form-label" for="Description">Description</label>
<textarea class="form-control" id="Description" name="Description" rows="5"><%= H(category.Description) %></textarea>
</div>

<div class="d-flex flex-wrap gap-2">
<button class="btn btn-primary" type="submit">Update Category</button>
<a class="btn btn-outline-secondary" href="/categories">Cancel</a>
</div>
</form>

<form method="post" action="/categories/<%= H(category.CategoryID) %>/delete" class="mt-3">
<button class="btn btn-outline-danger" type="submit">Delete Category</button>
</form>
</div>
</div>
</div>
</div>

+ 43
- 0
app/views/Categories/index.asp Dosyayı Görüntüle

@@ -0,0 +1,43 @@
<div class="d-flex align-items-center justify-content-between mb-4">
<div>
<h1 class="h3 mb-1">Categories</h1>
<p class="text-muted mb-0">Browse post categories from ASPBlogBrainOrdure.</p>
</div>
<a class="btn btn-primary" href="/categories/new">New Category</a>
</div>

<%
Dim categoryIter, categoryItem
Set categoryIter = categories.Iterator()

If categories.Count = 0 Then
%>
<div class="alert alert-secondary">No categories are available yet.</div>
<%
Else
%>
<div class="row gy-3">
<%
Do While categoryIter.HasNext
Set categoryItem = categoryIter.GetNext()
%>
<div class="col-12">
<article class="card shadow-sm">
<div class="card-body">
<h2 class="h5 mb-2">
<a href="/categories/<%= Server.URLEncode(CStr(categoryItem.CategoryID)) %>" class="text-decoration-none">
<%= H(categoryItem.Name) %>
</a>
</h2>
<p class="text-muted mb-3"><%= H(categoryItem.Description) %></p>
<a class="btn btn-sm btn-outline-primary" href="/categories/<%= Server.URLEncode(CStr(categoryItem.CategoryID)) %>">View</a>
</div>
</article>
</div>
<%
Loop
%>
</div>
<%
End If
%>

+ 31
- 0
app/views/Categories/new.asp Dosyayı Görüntüle

@@ -0,0 +1,31 @@
<div class="row">
<div class="col-lg-8">
<div class="card shadow-sm">
<div class="card-body">
<h1 class="h3 mb-4">New Category</h1>

<form method="post" action="/categories">
<div class="mb-3">
<label class="form-label" for="Name">Name</label>
<input class="form-control" type="text" id="Name" name="Name" required>
</div>

<div class="mb-3">
<label class="form-label" for="Slug">Slug</label>
<input class="form-control" type="text" id="Slug" name="Slug">
</div>

<div class="mb-4">
<label class="form-label" for="Description">Description</label>
<textarea class="form-control" id="Description" name="Description" rows="5"></textarea>
</div>

<div class="d-flex gap-2">
<button class="btn btn-primary" type="submit">Create Category</button>
<a class="btn btn-outline-secondary" href="/categories">Cancel</a>
</div>
</form>
</div>
</div>
</div>
</div>

+ 17
- 0
app/views/Categories/show.asp Dosyayı Görüntüle

@@ -0,0 +1,17 @@
<article class="card shadow-sm">
<div class="card-body">
<div class="mb-3">
<a href="/categories" class="small text-decoration-none">&larr; Back to categories</a>
</div>

<h1 class="h2 mb-3"><%= H(category.Name) %></h1>
<p class="fs-5 text-muted mb-4"><%= H(category.Description) %></p>

<div class="d-flex flex-wrap gap-2">
<a class="btn btn-outline-primary" href="/categories/<%= Server.URLEncode(CStr(category.CategoryID)) %>/edit">Edit Category</a>
<form method="post" action="/categories/<%= H(category.CategoryID) %>/delete">
<button class="btn btn-outline-danger" type="submit">Delete Category</button>
</form>
</div>
</div>
</article>

Yükleniyor…
İptal
Kaydet

Powered by TurnKey Linux.