Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: suggestion for clock:now #747

Merged
merged 6 commits into from
Nov 22, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions sample.org
Original file line number Diff line number Diff line change
Expand Up @@ -374,6 +374,7 @@ Next to units, =START= and =END= can also be expressed in dates like. Dates can
Some examples on how to use time ranges:

- =clock:..= searches for all items with time clocked. This includes headers that have time logged on their children.
- =clock:now= searches for currently clocked in headers.
- =sched:w= searches for all scheduled items in the current week (same for other units).
- =dead:..w= searches for all deadlines between now and the end of the week.
- =date:today= searches for all planning items (scheduled and deadline items) as well as items with active timestamps.
Expand Down
44 changes: 22 additions & 22 deletions src/colors.css
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
usage guide:
------------

this is supposed to document current usage,
this is supposed to document current usage,
it's not complete, not necessarily prescriptive and
some usages might need to be reconsidered to be more consistent

Expand All @@ -29,31 +29,31 @@
--yellow

additional colors:
--orange: TODO keyword, overdue planning dates
--orange: TODO keyword, overdue planning dates, active clock indicator
--red: error messages, changelog
--magenta: action button
--violet: unused

--green-soft: highlight selected table cell
*/
:root {
--base03: #002b36;
--base02: #073642;
--base01: #586e75;
--base00: #657b83;
--base0: #839496;
--base0-soft: rgba(131, 148, 150, 0.75);
--base1: #93a1a1;
--base1-soft: rgba(147, 161, 161, 0.4);
--base2: #eee8d5;
--base3: #fdf6e3;
--yellow: #b58900;
--orange: #cb4b16;
--red: #dc322f;
--magenta: #d33682;
--violet: #6c71c4;
--blue: #268bd2;
--cyan: #2aa198;
--green: #859900;
--green-soft: rgba(133, 153, 0, 0.28);
--base03: #002b36;
--base02: #073642;
--base01: #586e75;
--base00: #657b83;
--base0: #839496;
--base0-soft: rgba(131, 148, 150, 0.75);
--base1: #93a1a1;
--base1-soft: rgba(147, 161, 161, 0.4);
--base2: #eee8d5;
--base3: #fdf6e3;
--yellow: #b58900;
--orange: #cb4b16;
--red: #dc322f;
--magenta: #d33682;
--violet: #6c71c4;
--blue: #268bd2;
--cyan: #2aa198;
--green: #859900;
--green-soft: rgba(133, 153, 0, 0.28);
}
3 changes: 3 additions & 0 deletions src/components/OrgFile/components/ActionDrawer/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ const ActionDrawer = ({
isLoading,
online,
shouldDisableSyncButtons,
activeClocks,
}) => {
const [isDisplayingArrowButtons, setIsDisplayingArrowButtons] = useState(false);
const [isDisplayingCaptureButtons, setIsDisplayingCaptureButtons] = useState(false);
Expand Down Expand Up @@ -183,6 +184,7 @@ const ActionDrawer = ({
iconName={isDisplayingSearchButtons ? 'times' : 'search'}
isDisabled={false}
onClick={handleMainSearchButtonClick}
additionalClassName={activeClocks !== 0 ? 'active-clock-indicator' : undefined}
style={mainButtonStyle}
tooltip={
isDisplayingSearchButtons ? 'Hide Search / Task List' : 'Show Search / Task List'
Expand Down Expand Up @@ -402,6 +404,7 @@ const mapStateToProps = (state) => {
path,
isLoading: !state.base.get('isLoading').isEmpty(),
online: state.base.get('online'),
activeClocks: file.get('activeClocks'),
};
};

Expand Down
4 changes: 4 additions & 0 deletions src/components/OrgFile/components/ActionDrawer/stylesheet.css
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,7 @@
.action-drawer__capture-buttons-container {
position: relative;
}

.active-clock-indicator {
background-color: var(--orange);
}
6 changes: 6 additions & 0 deletions src/lib/clocking.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
import { subheadersOfHeaderWithIndex } from './org_utils';
import { dateForTimestamp } from './timestamps';

export const hasActiveClock = (header) => {
const logBookEntries = header.get('logBookEntries', []);
const activeEntries = logBookEntries.filter((entry) => entry.get('start') && !entry.get('end'));
return activeEntries.size !== 0;
};

const totalTimeLogged = (header) => {
const logBookEntries = header.get('logBookEntries', []);

Expand Down
4 changes: 3 additions & 1 deletion src/lib/parse_org.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import generateId from './id_generator';
import { updateHeadersTotalTimeLoggedRecursive } from './clocking';
import { hasActiveClock, updateHeadersTotalTimeLoggedRecursive } from './clocking';

import { fromJS, List } from 'immutable';
import _ from 'lodash';
Expand Down Expand Up @@ -890,9 +890,11 @@ export const parseOrg = (fileContents) => {
});

headers = updateHeadersTotalTimeLoggedRecursive(headers);
const activeClocks = fromJS(headers).filter(hasActiveClock).size;

return fromJS({
headers,
activeClocks,
todoKeywordSets,
fileConfigLines,
linesBeforeHeadings,
Expand Down
23 changes: 21 additions & 2 deletions src/reducers/org.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
updateHeadersTotalTimeLoggedRecursive,
totalFilteredTimeLogged,
updateHeadersTotalFilteredTimeLoggedRecursive,
hasActiveClock,
} from '../lib/clocking';

import {
Expand Down Expand Up @@ -66,7 +67,8 @@ export const parseFile = (state, action) => {
.setIn(['files', path, 'headers'], parsedFile.get('headers'))
.setIn(['files', path, 'todoKeywordSets'], parsedFile.get('todoKeywordSets'))
.setIn(['files', path, 'fileConfigLines'], parsedFile.get('fileConfigLines'))
.setIn(['files', path, 'linesBeforeHeadings'], parsedFile.get('linesBeforeHeadings'));
.setIn(['files', path, 'linesBeforeHeadings'], parsedFile.get('linesBeforeHeadings'))
.setIn(['files', path, 'activeClocks'], parsedFile.get('activeClocks'));
};

const clearSearch = (state) => state.setIn(['search', 'filteredHeaders'], null);
Expand Down Expand Up @@ -1053,6 +1055,7 @@ export const setLogEntryStop = (state, action) => {
const entryIndex = state
.getIn(['headers', headerIdx, 'logBookEntries'])
.findIndex((entry) => entry.get('id') === entryId);
state = state.update('activeClocks', (i) => i - 1);
return state.setIn(['headers', headerIdx, 'logBookEntries', entryIndex, 'end'], fromJS(time));
};

Expand All @@ -1064,6 +1067,7 @@ export const createLogEntryStart = (state, action) => {
start: time,
end: null,
});
state = state.update('activeClocks', (i) => i + 1);
return state.updateIn(['headers', headerIdx, 'logBookEntries'], (entries) =>
!!entries ? entries.unshift(newEntry) : List([newEntry])
);
Expand Down Expand Up @@ -1130,6 +1134,11 @@ const searchHeaders = ({ searchFilterExpr = [], headersToSearch, path }) => {
return filteredHeaders;
};

const isActiveClockFilter = (clockFilter) =>
clockFilter.field.timerange.type === 'point' &&
clockFilter.field.timerange.point.type === 'special' &&
clockFilter.field.timerange.point.value === 'now';

export const setSearchFilterInformation = (state, action) => {
const { searchFilter, cursorPosition, context } = action;

Expand Down Expand Up @@ -1167,9 +1176,13 @@ export const setSearchFilterInformation = (state, action) => {
const headers = files.map((file) => file.get('headers'));

// show clocked times & sum if there is a clock search term
const clockFilters = searchFilterExpr
const clockedTimeAndActiveClockFilters = searchFilterExpr
.filter((f) => f.type === 'field')
.filter((f) => f.field.type === 'clock');
const clockFilters = clockedTimeAndActiveClockFilters.filter((f) => !isActiveClockFilter(f));
// check for special case "clock:now" which searches active clocks
const hasActiveClockFilter = clockedTimeAndActiveClockFilters.length !== clockFilters.length;

const filterFunctions = clockFilters.map(timeFilter);
const showClockedTimes = clockFilters.length !== 0;
state.setIn(['search', 'showClockedTimes'], showClockedTimes);
Expand All @@ -1186,6 +1199,12 @@ export const setSearchFilterInformation = (state, action) => {
);
}

if (hasActiveClockFilter) {
headersToSearch = headersToSearch.map((headersOfFile) =>
headersOfFile.filter(hasActiveClock)
);
}

// calculate relevant clocked times and total
if (showClockedTimes) {
headersToSearch = headersToSearch.map((headersOfFile) =>
Expand Down