Skip to content
This repository has been archived by the owner on Jul 6, 2023. It is now read-only.

Commit

Permalink
feat(Commit): Display diff between 2 commits
Browse files Browse the repository at this point in the history
  • Loading branch information
ahmadalfy committed Feb 6, 2020
1 parent f6d56f4 commit 5302713
Show file tree
Hide file tree
Showing 16 changed files with 2,643 additions and 4 deletions.
13 changes: 13 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,19 @@ <h1 class="panel__title">Commits</h1>
</div>
<div class="panel__footer"></div>
</div>
<div class="panel" id="diffs-panel">
<div class="panel__head">
<h1 class="panel__title">Files changed</h1>
<div class="panel__actions" id="diffs-filters">
<div class="panel__actions-list" id="diffs-filters"></div>
<button class="close-panel">Close</button>
</div>
</div>
<div class="panel__content">
<div id="diffs-content"></div>
</div>
<div class="panel__footer"></div>
</div>
</div>
<script type="module" src="scripts/app.js"></script>
</body>
Expand Down
50 changes: 50 additions & 0 deletions package-lock.json

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

2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
"dexie": "^2.0.4",
"dexie-export-import": "^1.0.0-rc.1",
"dexie-relationships": "^1.2.11",
"diff2html": "^3.0.2",
"downloadjs": "^1.4.7",
"highcharts": "^8.0.0",
"javascript-time-ago": "^2.0.6",
Expand All @@ -43,6 +44,7 @@
"dexie",
"dexie-export-import",
"dexie-relationships",
"diff2html/bundles/js/diff2html.min.js",
"downloadjs",
"highcharts",
"javascript-time-ago",
Expand Down
27 changes: 27 additions & 0 deletions scripts/projects.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { html, render } from '../web_modules/lit-html.js';
import Diff2Html from '../web_modules/diff2html/bundles/js/diff2html.min.js';
import Utilities from './utilities.js';
import routes from './routes.js';
import Groups from './groups.js';
Expand Down Expand Up @@ -63,6 +64,10 @@ class Projects extends Base {
return Utilities.req(`${routes.projects}/${projectId}/${routes.repository}/${routes.commits}`, searchParams);
}

loadCommit(projectId, commitId) {
return Utilities.req(`${routes.projects}/${projectId}/${routes.repository}/${routes.commits}/${commitId}/diff`);
}

drawListing(projects) {
const projectsTemplates = [];
for (const project of projects) {
Expand Down Expand Up @@ -239,6 +244,9 @@ class Projects extends Base {
<td>${new Date(commit.authored_date).toTimeString().split(' ')[0]}</td>
<td class="additions">+${commit.stats.additions}</td>
<td class="deletions">-${commit.stats.deletions}</td>
<td>
<button @click=${() => {this.getCommitDetails(projectId, commit.short_id);}}>Details</button>
</td>
</tr>
`);
}
Expand All @@ -252,6 +260,7 @@ class Projects extends Base {
<th rowspan="2">Author</th>
<th rowspan="2">Time</th>
<th colspan="2">Statistics</th>
<th rowspan="2">Actions</th>
</tr>
<tr>
<th>Additions</th>
Expand All @@ -266,6 +275,24 @@ class Projects extends Base {
render(nodes, document.querySelector('#commits-content'));
}

async getCommitDetails(projectId, commitId) {
const commit = await this.loadCommit(projectId, commitId);
this.constructDiffString(commit);
}

constructDiffString(commit) {
const diffs = [];
commit.forEach(change => {
diffs.push(`diff --git a/${change.old_path} b/${change.new_path}`);
if (change.new_file) {
diffs.push(`new file mode ${change.b_mode}`);
}
diffs.push(change.diff);
});
document.querySelector('#diffs-panel').style.display = 'flex';
document.querySelector('#diffs-content').innerHTML = Diff2Html.html(diffs.join('\n'));
}

checkData() {
db.projects.with({ group: 'group_id'}).then(projects => {
this.drawListing(projects);
Expand Down
15 changes: 15 additions & 0 deletions styles/components/commit-details.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
.d2h-code-linenumber {
position: static;
display: table-cell;
vertical-align: top;
}

.d2h-diff-table {
table-layout: fixed;
}

.d2h-file-list-title {
font-size: 14px;
margin: 10px 0 0 10px;
display: block;
}
7 changes: 7 additions & 0 deletions styles/components/layout.css
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,10 @@
display: none;
background: #fff;
}

#diffs-panel {
grid-area: members-start / members-start / data-end / data-end;
z-index: 1;
display: none;
background: #fff;
}
4 changes: 4 additions & 0 deletions styles/main.css
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,11 @@
@import "./objects/listings.css";
@import "./objects/panels.css";

/* Vendor */
@import "./vendor/diff2html.css";

/* Components */
@import "./components/layout.css";
@import "./components/app-header.css";
@import "./components/commits-list.css";
@import "./components/commit-details.css";
1 change: 1 addition & 0 deletions styles/vendor/diff2html.css

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

15 changes: 15 additions & 0 deletions web_modules/common/_commonjsHelpers-7dcf7119.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};

function unwrapExports (x) {
return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;
}

function createCommonjsModule(fn, module) {
return module = { exports: {} }, fn(module, module.exports), module.exports;
}

function getCjsExportFromNamespace (n) {
return n && n['default'] || n;
}

export { commonjsGlobal as a, createCommonjsModule as c, getCjsExportFromNamespace as g, unwrapExports as u };
2 changes: 1 addition & 1 deletion web_modules/dexie-relationships.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import require$$0 from './dexie.js';
import { c as createCommonjsModule, a as commonjsGlobal } from './common/_commonjsHelpers-28d57e96.js';
import { c as createCommonjsModule, a as commonjsGlobal } from './common/_commonjsHelpers-7dcf7119.js';

var dist = createCommonjsModule(function (module, exports) {
(function (global, factory) {
Expand Down
Loading

0 comments on commit 5302713

Please sign in to comment.