Skip to content

Commit

Permalink
Add all links views chart and update README.md file
Browse files Browse the repository at this point in the history
  • Loading branch information
mdromi committed Feb 12, 2024
1 parent 0b8e8f6 commit 485ec30
Show file tree
Hide file tree
Showing 4 changed files with 95 additions and 39 deletions.
88 changes: 75 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,77 @@
# URL Shortener

## Requirements

* Submit a url in a form on the homepage
* Url is saved to the database
* The URL can be viewed by accessing a Base62 encoded primary key ID (short code) of the URL /v/:id
* A user should be able to copy the short URL to the clipboard
* When visiting the short code, a view is recorded so we can keep track of how many views per day a link gets
* A user should be able to view graph of the views over the past 2 weeks
* A user should be able to edit and delete URL
* We should also retrieve the title, description, and open graph image for the HTML document
* This should run in the background to keep the application fast
* If a URL is edited, we should updated the title, description, and image for it
* We should paginate the last of shorted URLs
## Introduction

This is a URL Shortener web application that allows users to shorten URLs and track their views over time. It also provides administrative functionalities for managing users, links, and guest users.

## Features

### User Features

1. Submit a URL in a form on the homepage.
2. URLs are saved to the database.
3. Access URLs using a Base62 encoded primary key ID (short code) of the URL (/v/:id).
4. Copy the short URL to the clipboard.
5. Record views when visiting the short code to track views per day.
6. View a graph of the views over the past 2 weeks.
7. Edit and delete URLs.
8. Retrieve the title, description, and open graph image for the HTML document.
- This runs in the background to keep the application fast.
- Update title, description, and image if a URL is edited.
9. Paginate the list of shortened URLs.

### Admin Features

- **Dashboard**
- Show all registered users and guest users on a diagram.
- Users Chart (Last 7 Days).
- All Links Views (Last 2 weeks).

- **Users**
- Show the list of all users.
- Display the total number of links created by each user.
- View user profiles.
- Display basic information about the user.
- Show all links views for the last 2 weeks.
- Display all links created by the user.
- Edit links as an admin.
- Destroy or edit users and links.

- **Guest User**
- Show the list of all guest users.
- Show their IP addresses.

## Technologies Used

- Ruby on Rails for the backend
- PostgreSQL for the database
- Devise for authentication
- Chartkick for generating charts
- Pagy for generating pagination
- Background job processing (e.g., Sidekiq, Delayed Job) for fetching metadata asynchronously
- Tailwind CSS for front-end design and layout

## Installation and Setup

1. Clone the repository (`git clone https://github.com/Mdromi/url_shortener`).
2. Install Ruby and Rails dependencies (`bundle install`).
3. Set up the database (`rails db:setup`).
4. Start the Rails server (`rails server`).
5. Visit `http://localhost:3000` in your web browser.

## Usage

1. Register or log in to the application.
2. Shorten a URL by submitting it on the homepage.
3. View, edit, or delete URLs from your dashboard.
4. View URL statistics and graphs.
5. Access admin functionalities from the admin panel.

## Contributors

- [Md Romi](https://github.com/mdromi)
- [Live](https://url-shortener-qkvt.onrender.com/)

## License

This project is licensed under the [MIT License](LICENSE).
19 changes: 16 additions & 3 deletions app/controllers/admin/dashboard_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,23 @@ class Admin::DashboardController < ApplicationController
before_action :authorize_admin! # Ensure user is authorized as an admin

def index
@registered_users_amount = registered_users_amount
@guest_user_links_amount = guest_user_links_amount
@all_users_amount = all_users_amount
@registered_users_amount = registered_users_amount
@guest_user_links_amount = guest_user_links_amount
@all_users_amount = all_users_amount
@links ||= Link.all

# Initialize a hash to store total views for each day
@link_views_data = Hash.new(0)

# Iterate over each link and aggregate views for each day
@links.each do |link|
link.views.group_by_day(:created_at, range: 2.weeks.ago..Time.now, expand_range: true).count.each do |day, views|
@link_views_data[day] += views
end
end
end



def show
end
Expand Down
4 changes: 4 additions & 0 deletions app/views/admin/dashboard/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@
<h2 class="text-lg leading-6 font-medium text-gray-900">Users Chart (Last 7 Days)</h2>
<%== line_chart user_signups_data(7), download: true, height: '300px' %>
</div>
<div class="mt-10">
<h2 class="text-lg leading-6 font-medium p-4 text-gray-900">All Links Views (Last 2 weeks)</h2>
<%= line_chart @link_views_data, library: { title: { text: 'Total Views of All Links per Day' } } %>
</div>
</dl>
</div>
</div>
23 changes: 0 additions & 23 deletions task.txt

This file was deleted.

0 comments on commit 485ec30

Please sign in to comment.