Skip to content

Commit

Permalink
feat: show date and author in history view
Browse files Browse the repository at this point in the history
close #691
  • Loading branch information
Vinzent03 committed Feb 29, 2024
1 parent 4544cac commit a6e33d3
Show file tree
Hide file tree
Showing 7 changed files with 152 additions and 23 deletions.
2 changes: 2 additions & 0 deletions src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ export const DEFAULT_SETTINGS: Omit<ObsidianGitSettings, "autoCommitMessage"> =
submoduleRecurseCheckout: false,
gitDir: "",
showFileMenu: true,
authorInHistoryView: "hide",
dateInHistoryView: false,
lineAuthor: {
show: false,
followMovement: "inactive",
Expand Down
4 changes: 4 additions & 0 deletions src/gitManager/isomorphicGit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -782,6 +782,10 @@ export class IsomorphicGit extends GitManager {

return {
message: completeMessage[0],
author: {
name: log.commit.author.name,
email: log.commit.author.email,
},
body: completeMessage.slice(1).join("\n\n"),
date: new Date(
log.commit.committer.timestamp
Expand Down
6 changes: 5 additions & 1 deletion src/gitManager/simpleGit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -553,8 +553,12 @@ export class SimpleGit extends GitManager {
(err) => this.onError(err)
);

return res.all.map((e) => ({
return res.all.map<LogEntry>((e) => ({
...e,
author: {
name: e.author_name,
email: e.author_email,
},
refs: e.refs.split(", "),
diff: {
...e.diff!,
Expand Down
46 changes: 44 additions & 2 deletions src/setting/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,11 @@ import {
LineAuthorTimezoneOption,
} from "src/lineAuthor/model";
import ObsidianGit from "src/main";
import { ObsidianGitSettings, SyncMethod } from "src/types";
import {
ObsidianGitSettings,
ShowAuthorInHistoryView,
SyncMethod,
} from "src/types";
import { convertToRgb, rgbToString, formatMinutes } from "src/utils";

const FORMAT_STRING_REFERENCE_URL =
Expand Down Expand Up @@ -420,7 +424,43 @@ export class ObsidianGitSettingsTab extends PluginSettingTab {
}

containerEl.createEl("br");
containerEl.createEl("h3", { text: "Miscellaneous" });
containerEl.createEl("h3", { text: "History View" });

new Setting(containerEl)
.setName("Show Author")
.setDesc("Show the author of the commit in the history view")
.addDropdown((dropdown) => {
const options: Record<ShowAuthorInHistoryView, string> = {
hide: "Hide",
full: "Full",
initials: "Initials",
};
dropdown.addOptions(options);
dropdown.setValue(plugin.settings.authorInHistoryView);
dropdown.onChange(async (option: ShowAuthorInHistoryView) => {
plugin.settings.authorInHistoryView = option;
plugin.saveSettings();
plugin.refresh();
});
});

new Setting(containerEl)
.setName("Show Date")
.setDesc(
"Show the date of the commit in the history view. The {{date}} placeholder format is used to display the date."
)
.addToggle((toggle) =>
toggle
.setValue(plugin.settings.dateInHistoryView)
.onChange((value) => {
plugin.settings.dateInHistoryView = value;
plugin.saveSettings();
plugin.refresh();
})
);

containerEl.createEl("br");
containerEl.createEl("h3", { text: "Source Control View" });

new Setting(containerEl)
.setName(
Expand Down Expand Up @@ -458,6 +498,8 @@ export class ObsidianGitSettingsTab extends PluginSettingTab {
plugin.setRefreshDebouncer();
})
);
containerEl.createEl("br");
containerEl.createEl("h3", { text: "Miscellaneous" });

new Setting(containerEl)
.setName("Disable notifications")
Expand Down
8 changes: 8 additions & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ export interface ObsidianGitSettings {
setLastSaveToLastCommit: boolean;
gitDir: string;
showFileMenu: boolean;
authorInHistoryView: ShowAuthorInHistoryView;
dateInHistoryView: boolean;
}

/**
Expand All @@ -59,6 +61,8 @@ export function mergeSettingsByPriority(

export type SyncMethod = "rebase" | "merge" | "reset";

export type ShowAuthorInHistoryView = "full" | "initials" | "hide";

export interface Author {
name: string;
email: string;
Expand Down Expand Up @@ -204,6 +208,10 @@ export interface LogEntry {
refs: string[];
body: string;
diff: DiffEntry;
author: {
name: string;
email: string;
};
}

export interface DiffEntry {
Expand Down
36 changes: 33 additions & 3 deletions src/ui/history/components/logComponent.svelte
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<script lang="ts">
import { moment } from "obsidian";
import ObsidianGit from "src/main";
import { LogEntry } from "src/types";
import { slide } from "svelte/transition";
Expand All @@ -19,6 +20,17 @@
$: side = (view.leaf.getRoot() as any).side == "left" ? "right" : "left";
let isCollapsed = true;
function authorToString(log: LogEntry) {
const name = log.author.name;
if (plugin.settings.authorInHistoryView == "full") {
return name;
} else if (plugin.settings.authorInHistoryView == "initials") {
const words = name.split(" ").filter((word) => word.length > 0);
return words.map((word) => word[0].toUpperCase()).join("");
}
}
</script>

<!-- svelte-ignore a11y-click-events-have-key-events -->
Expand Down Expand Up @@ -53,6 +65,27 @@
{log.refs.join(", ")}
</div>
{/if}
{#if plugin.settings.authorInHistoryView != "hide" && log.author?.name}
<div
class="git-author"
aria-label={log.author.name}
data-tooltip-position={side}
>
{authorToString(log)}
</div>
{/if}
{#if plugin.settings.dateInHistoryView}
<div
class="git-date"
aria-label={log.date}
data-tooltip-position={side}
>
{moment(log.date).format(
plugin.settings.commitDateFormat
)}
</div>
{/if}

<div
class="tree-item-inner nav-folder-title-content"
aria-label={log.message}
Expand Down Expand Up @@ -85,7 +118,4 @@
</main>

<style lang="scss">
.git-ref {
color: var(--text-accent);
}
</style>
73 changes: 56 additions & 17 deletions styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,20 @@
}
}

.workspace-leaf-content[data-type='git-view'] .button-border {
.workspace-leaf-content[data-type="git-view"] .button-border {
border: 2px solid var(--interactive-accent);
border-radius: var(--radius-s);
}

.workspace-leaf-content[data-type='git-view'] .view-content {
.workspace-leaf-content[data-type="git-view"] .view-content {
padding: 0;
}

.workspace-leaf-content[data-type='git-history-view'] .view-content {
.workspace-leaf-content[data-type="git-history-view"] .view-content {
padding: 0;
}

.loading>svg {
.loading > svg {
animation: 2s linear infinite loading;
transform-origin: 50% 50%;
display: inline-block;
Expand Down Expand Up @@ -77,6 +77,18 @@
height: auto;
}

.git-author {
color: var(--text-accent);
}

.git-date {
color: var(--text-accent);
}

.git-ref {
color: var(--text-accent);
}

.workspace-leaf-content[data-type="diff-view"] .d2h-d-none {
display: none;
}
Expand Down Expand Up @@ -228,12 +240,18 @@
}

.theme-light .workspace-leaf-content[data-type="diff-view"] .d2h-code-line del,
.theme-light .workspace-leaf-content[data-type="diff-view"] .d2h-code-side-line del {
.theme-light
.workspace-leaf-content[data-type="diff-view"]
.d2h-code-side-line
del {
background-color: #ffb6ba;
}

.theme-dark .workspace-leaf-content[data-type="diff-view"] .d2h-code-line del,
.theme-dark .workspace-leaf-content[data-type="diff-view"] .d2h-code-side-line del {
.theme-dark
.workspace-leaf-content[data-type="diff-view"]
.d2h-code-side-line
del {
background-color: #8d232881;
}

Expand All @@ -249,13 +267,19 @@
}

.theme-light .workspace-leaf-content[data-type="diff-view"] .d2h-code-line ins,
.theme-light .workspace-leaf-content[data-type="diff-view"] .d2h-code-side-line ins {
.theme-light
.workspace-leaf-content[data-type="diff-view"]
.d2h-code-side-line
ins {
background-color: #97f295;
text-align: left;
}

.theme-dark .workspace-leaf-content[data-type="diff-view"] .d2h-code-line ins,
.theme-dark .workspace-leaf-content[data-type="diff-view"] .d2h-code-side-line ins {
.theme-dark
.workspace-leaf-content[data-type="diff-view"]
.d2h-code-side-line
ins {
background-color: #1d921996;
text-align: left;
}
Expand Down Expand Up @@ -376,19 +400,31 @@
color: var(--text-normal);
}

.theme-light .workspace-leaf-content[data-type="diff-view"] .d2h-file-diff .d2h-del.d2h-change {
.theme-light
.workspace-leaf-content[data-type="diff-view"]
.d2h-file-diff
.d2h-del.d2h-change {
background-color: #fdf2d0;
}

.theme-dark .workspace-leaf-content[data-type="diff-view"] .d2h-file-diff .d2h-del.d2h-change {
.theme-dark
.workspace-leaf-content[data-type="diff-view"]
.d2h-file-diff
.d2h-del.d2h-change {
background-color: #55492480;
}

.theme-light .workspace-leaf-content[data-type="diff-view"] .d2h-file-diff .d2h-ins.d2h-change {
.theme-light
.workspace-leaf-content[data-type="diff-view"]
.d2h-file-diff
.d2h-ins.d2h-change {
background-color: #ded;
}

.theme-dark .workspace-leaf-content[data-type="diff-view"] .d2h-file-diff .d2h-ins.d2h-change {
.theme-dark
.workspace-leaf-content[data-type="diff-view"]
.d2h-file-diff
.d2h-ins.d2h-change {
background-color: rgba(37, 78, 37, 0.418);
}

Expand All @@ -401,7 +437,9 @@
text-decoration: none;
}

.workspace-leaf-content[data-type="diff-view"] .d2h-file-list-wrapper a:visited {
.workspace-leaf-content[data-type="diff-view"]
.d2h-file-list-wrapper
a:visited {
color: #3572b0;
}

Expand All @@ -427,13 +465,13 @@
padding: 0;
}

.workspace-leaf-content[data-type="diff-view"] .d2h-file-list>li {
.workspace-leaf-content[data-type="diff-view"] .d2h-file-list > li {
border-bottom: 1px solid var(--background-modifier-border);
margin: 0;
padding: 5px 10px;
}

.workspace-leaf-content[data-type="diff-view"] .d2h-file-list>li:last-child {
.workspace-leaf-content[data-type="diff-view"] .d2h-file-list > li:last-child {
border-bottom: none;
}

Expand Down Expand Up @@ -501,9 +539,10 @@
background-color: var(--background-secondary);
}

.cm-gutterElement.obs-git-blame-gutter > div, .line-author-settings-preview {
.cm-gutterElement.obs-git-blame-gutter > div,
.line-author-settings-preview {
/* delegate text color to settings */
color: var(--obs-git-gutter-text);
color: var(--obs-git-gutter-text);
font-family: monospace;
height: 100%; /* ensure, that age-based background color occupies entire parent */
text-align: right;
Expand Down

0 comments on commit a6e33d3

Please sign in to comment.