Skip to content

Commit

Permalink
Add changelog inside the application (#1172)
Browse files Browse the repository at this point in the history
  • Loading branch information
djaiss authored Apr 14, 2018
1 parent cb3fe20 commit ad2b75d
Show file tree
Hide file tree
Showing 36 changed files with 591 additions and 83 deletions.
2 changes: 1 addition & 1 deletion .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,5 @@
#### Other tasks
- [ ] [CHANGELOG](https://github.com/monicahq/monica/blob/master/CHANGELOG) entry added, if necessary, under `UNRELEASED`.
- [ ] [CONTRIBUTORS](https://github.com/monicahq/monica/blob/master/CONTRIBUTORS) entry added, if necessary.
- [ ] If it's relevant, add the documentation about your feature in the README file.
- [ ] If it's relevant and worth mentioning, create a changelog entry for this change. The changelog entry will appear inside the UI for all users to see. To know if your change is worth the creation of a changelog entry, [read the documentation](https://github.com/monicahq/monica/wiki/Advanced-content-tips-for-developers#when-is-it-relevant-to-create-a-changelog-entry).
- [ ] Indicate `[wip]` in the title of the PR it is is not final yet. Remove `[wip]` when ready. Otherwise the PR will be considered complete and rejected if it's not working.
1 change: 1 addition & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
UNRELEASED CHANGES:

* Add a changelog inside the application
* Fix monica:calculatestatistics command

RELEASED VERSIONS:
Expand Down
13 changes: 13 additions & 0 deletions app/Account.php
Original file line number Diff line number Diff line change
Expand Up @@ -775,4 +775,17 @@ public function getYearlyActivitiesStatistics()

return $activitiesStatistics;
}

/**
* Add the given changelog entry and mark it unread for all users in this
* account.
*
* @param int $changelogId
*/
public function addUnreadChangelogEntry(int $changelogId)
{
foreach ($this->users as $user) {
$user->changelogs()->syncWithoutDetaching([$changelogId => ['read' => 0]]);
}
}
}
45 changes: 45 additions & 0 deletions app/Changelog.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?php

namespace App;

use Parsedown;
use App\Helpers\DateHelper;
use Illuminate\Database\Eloquent\Model;

class Changelog extends Model
{
/**
* The attributes that aren't mass assignable.
*
* @var array
*/
protected $guarded = ['id'];

/**
* Get the user records associated with the tag.
*/
public function users()
{
return $this->belongsToMany('App\User')->withPivot('read', 'upvote')->withTimestamps();
}

/**
* Return the markdown parsed description.
*
* @return string
*/
public function getDescriptionAttribute($value)
{
return (new Parsedown())->text($value);
}

/**
* Return the created_at date in a friendly format.
*
* @return string
*/
public function getCreatedAtAttribute($value)
{
return DateHelper::getShortDate($value);
}
}
25 changes: 25 additions & 0 deletions app/Http/Controllers/ChangelogController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

namespace App\Http\Controllers;

use Auth;
use App\Changelog;
use Illuminate\Http\Request;

class ChangelogController extends Controller
{
/**
* Display a listing of the resource.
*
* @param Request $request
* @return \Illuminate\Http\Response
*/
public function index(Request $request)
{
$changelogs = auth()->user()->changelogs()->orderBy('created_at', 'desc')->get();

auth()->user()->markChangelogAsRead();

return view('changelog.index')->withChangelogs($changelogs);
}
}
4 changes: 3 additions & 1 deletion app/Http/Controllers/SettingsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ class SettingsController extends Controller
'activity_types',
'api_usage',
'cache',
'changelog_user',
'changelogs',
'countries',
'currencies',
'default_contact_field_types',
Expand Down Expand Up @@ -119,7 +121,7 @@ public function delete(Request $request)

$account = auth()->user()->account;

if ($account->isSubscribed()) {
if ($account->isSubscribed() && auth()->user()->has_access_to_paid_version_for_free == 0) {
$account->subscription($account->getSubscribedPlanName())->cancelNow();
}

Expand Down
14 changes: 14 additions & 0 deletions app/Instance.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace App;

use DB;
use App\Jobs\AddChangelogEntry;
use Illuminate\Database\Eloquent\Model;

class Instance extends Model
Expand All @@ -18,4 +19,17 @@ public function markDefaultContactFieldTypeAsMigrated()
DB::table('default_contact_field_types')
->update(['migrated' => 1]);
}

/**
* Create a job to add a changelog entry for each account of the instance.
*
* @param int $changelogId
*/
public function addUnreadChangelogEntry(int $changelogId)
{
$accounts = \App\Account::all();
foreach ($accounts as $account) {
AddChangelogEntry::dispatch($account, $changelogId);
}
}
}
42 changes: 42 additions & 0 deletions app/Jobs/AddChangelogEntry.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?php

namespace App\Jobs;

use App\Account;
use Illuminate\Bus\Queueable;
use Illuminate\Queue\SerializesModels;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;

/**
* This job adds a changelog entry for all users in a given account.
*/
class AddChangelogEntry implements ShouldQueue
{
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;

protected $account;
protected $changelogId;

/**
* Create a new job instance.
*
* @return void
*/
public function __construct(Account $account, int $changelogId)
{
$this->account = $account;
$this->changelogId = $changelogId;
}

/**
* Execute the job.
*
* @return void
*/
public function handle()
{
$this->account->addUnreadChangelogEntry($this->changelogId);
}
}
31 changes: 31 additions & 0 deletions app/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace App;

use DB;
use Carbon\Carbon;
use Laravel\Passport\HasApiTokens;
use Illuminate\Notifications\Notifiable;
Expand Down Expand Up @@ -73,6 +74,14 @@ public function account()
return $this->belongsTo('App\Account');
}

/**
* Get the changelog records associated with the user.
*/
public function changelogs()
{
return $this->belongsToMany('App\Changelog')->withPivot('read', 'upvote')->withTimestamps();
}

/**
* Assigns a default value just in case the sort order is empty.
*
Expand Down Expand Up @@ -241,4 +250,26 @@ public function shouldBeReminded(Carbon $date)

return true;
}

/**
* Check if user has one or more unread changelog entries.
*
* @return bool
*/
public function hasUnreadChangelogs()
{
return $this->changelogs()->wherePivot('read', 0)->count() > 0;
}

/**
* Mark all changelog entries as read.
*
* @return void
*/
public function markChangelogAsRead()
{
DB::table('changelog_user')
->where('user_id', $this->id)
->update(['read' => 1]);
}
}
8 changes: 8 additions & 0 deletions database/factories/ModelFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,14 @@
];
});

$factory->define(App\Changelog::class, function (Faker\Generator $faker) {
return [];
});

$factory->define(App\Instance::class, function (Faker\Generator $faker) {
return [];
});

$factory->define(\Laravel\Cashier\Subscription::class, function (Faker\Generator $faker) {
static $account_id;
static $stripe_plan;
Expand Down
30 changes: 30 additions & 0 deletions database/migrations/2018_04_13_205231_create_changes_table.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php

use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class CreateChangesTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('changelogs', function (Blueprint $table) {
$table->increments('id');
$table->mediumText('description');
$table->timestamps();
});

Schema::create('changelog_user', function (Blueprint $table) {
$table->integer('changelog_id');
$table->integer('user_id');
$table->boolean('read')->default(0);
$table->boolean('upvote')->default(0);
$table->timestamps();
});
}
}
45 changes: 45 additions & 0 deletions database/migrations/2018_04_13_230536_update_changelog.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?php

use Illuminate\Database\Migrations\Migration;

class UpdateChangelog extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
$description = '
**Introducing a new product changes section**
There is a new header now in Monica. It shows a bell that slowly pulsate, with a red dot, if there is a new feature or an important change in the application. You will not have to find out by yourself what has changed in the product.
![image](/img/changelogs/2018-04-14-new-product-section.png)';

$id = DB::table('changelogs')->insertGetId([
'description' => $description,
'created_at' => '2018-04-15',
]);

$instance = \App\Instance::first();
$instance->addUnreadChangelogEntry($id);

$description = '
**New relationships**
You now have much more control on how you link contacts together.
Before you could only have parent/child relationships and significant other relationships. Now you can have much more types of relationships, like uncle/nephew, lover, coworker, and so on. We hope you will like what we have done.
![image](/img/changelogs/2018-04-14-relationships.png)';

$id = DB::table('changelogs')->insertGetId([
'description' => $description,
'created_at' => \Carbon\Carbon::now(),
]);

$instance->addUnreadChangelogEntry($id);
}
}
2 changes: 1 addition & 1 deletion public/css/app.css

Large diffs are not rendered by default.

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion public/js/app.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion public/js/langs/en.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion public/js/langs/fr.json

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions public/js/langs/la.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[]
2 changes: 1 addition & 1 deletion public/js/langs/pt.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion public/js/manifest.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion public/js/vendor.js

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions public/mix-manifest.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"/js/app.js": "/js/app.js?id=ddb011814d41693d9c81",
"/css/app.css": "/css/app.css?id=a760618775a6eaf349c1",
"/js/app.js": "/js/app.js?id=0b47a1c14e2467588242",
"/css/app.css": "/css/app.css?id=50497e2c042457a7cc7b",
"/css/stripe.css": "/css/stripe.css?id=64c68c04c4e475fcc7c6",
"/js/vendor.js": "/js/vendor.js?id=490bf428af4c7224b600",
"/js/vendor.js": "/js/vendor.js?id=09ba43dec0e7c5c38705",
"/js/stripe.js": "/js/stripe.js?id=e2284957ba723a52a4b7",
"/js/manifest.js": "/js/manifest.js?id=7999d63793f040b855fb"
"/js/manifest.js": "/js/manifest.js?id=0225916a5d4fbc86a881"
}
15 changes: 13 additions & 2 deletions resources/assets/sass/app.scss
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,29 @@ $border-color: #dfdfdf;
@import "marketing";
@import "settings";
@import "modal";
@import "changelog";

// Custom colors
// Extending Tachyions
.bg-gray-monica {
background-color: #f2f4f8;
}

.bg-blue-monica {
background-color: #325776;
}

.b--gray-monica {
border-color: #dde2e9;
}
.w-5 { width: 5%; }
.w-95 { width: 95%; }

.w-5 {
width: 5%;
}

.w-95 {
width: 95%;
}

.form-error-message {
border-top: 1px solid #ed6246;
Expand Down
7 changes: 7 additions & 0 deletions resources/assets/sass/changelog.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
.changelog {
img {
max-width: 100%;
border: 1px solid #e5e5e5;
padding: 3px;
}
}
Loading

0 comments on commit ad2b75d

Please sign in to comment.